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
          主站蜘蛛池模板: 五大连池市| 分宜县| 濮阳县| 阳城县| 和平区| 同心县| 云浮市| 卓尼县| 灌云县| 汝州市| 荆州市| 比如县| 斗六市| 宁晋县| 精河县| 松江区| 宁武县| 额尔古纳市| 湘潭市| 江山市| 乳山市| 定兴县| 永胜县| 宜丰县| 上犹县| 时尚| 隆昌县| 临海市| 澄江县| 五大连池市| 介休市| 剑河县| 廊坊市| 烟台市| 定兴县| 鄂托克旗| 苍溪县| 汉阴县| 密云县| 梨树县| 博爱县|