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 閱讀(634) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 曲阜市| 大埔区| 利辛县| 宿松县| 大理市| 石景山区| 如皋市| 偃师市| 砀山县| 南康市| 安义县| 湘乡市| 瑞昌市| 舞阳县| 双辽市| 湾仔区| 从江县| 石台县| 安宁市| 榆树市| 清远市| 大同县| 龙山县| 龙里县| 密云县| 长海县| 衡阳县| 德令哈市| 太仆寺旗| 平阴县| 莱州市| 汉川市| 新宁县| 汝州市| 赣州市| 集安市| 昂仁县| 蓝田县| 玉环县| 太和县| 辽阳市|