posts - 38,  comments - 22,  trackbacks - 0

           /**
            *
            * @param value 要四舍五入的值
            * @param scale 小數點后要取的位數
            * @return
            */
           public static double round(double value,int scale){
           BigDecimal bd=new BigDecimal(value);
           BigDecimal divisor=new BigDecimal(1);
           BigDecimal returnValue=bd.divide(divisor, scale,BigDecimal.ROUND_HALF_UP );
           return returnValue.doubleValue();
           }


          txt.addFocusListener(new FocusAdapter() {
              public void focusLost(FocusEvent e) {
               if (e.isTemporary()) {
                return;
               }
               checkFullSize(txt, "人名", 20);
              }
             });
          public boolean checkFullSize(JTextComponent comp, String desc, int digit) {

            if (checkHarf(comp.getText())) {
             comp.requestFocus();
             JOptionPane.showMessageDialog(null, "full size");
             comp.requestFocus();
             return false;
            }

            if (comp.getText().length() > digit) {
             JOptionPane.showMessageDialog(null, "exceed digit");
             comp.requestFocus();
             return false;
            }

            return true;
           }

           /**
            * 是否為半角
            * @param 字符串
            * @return 半角true 全角false
            */
           private boolean checkHarf(String item) {

            byte[] bytes = item.getBytes();
            int beams = item.length();
            if (beams == bytes.length) {
             return true;
            } else {
             return false;
            }
           }

          posted on 2007-04-09 09:22 aaabbb 閱讀(640) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 乌什县| 阿荣旗| 常山县| 静安区| 固镇县| 永州市| 蛟河市| 四川省| 涟水县| 江西省| 额敏县| 中阳县| 永兴县| 东莞市| 大石桥市| 龙海市| 乌拉特中旗| 邻水| 庄浪县| 轮台县| 巴楚县| 革吉县| 南澳县| 兴山县| 铜陵市| 宜川县| 西林县| 山东省| 冀州市| 陕西省| 天津市| 仲巴县| 章丘市| 惠水县| 张家港市| 尉氏县| 达日县| 河间市| 泗水县| 高雄市| 沽源县|