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
          主站蜘蛛池模板: 华坪县| 治多县| 区。| 彰化县| 临漳县| 介休市| 大竹县| 梨树县| 临海市| 广河县| 宿迁市| 井研县| 桃园县| 大化| 武平县| 洪湖市| 宜丰县| 哈尔滨市| 旺苍县| 寻乌县| 阿拉善盟| 通城县| 蛟河市| 台南县| 通江县| 荣成市| 太仓市| 板桥市| 长沙县| 山东| 福安市| 桑日县| 固镇县| 叙永县| 巴彦淖尔市| 武宁县| 互助| 呼和浩特市| 河源市| 越西县| 大英县|