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
          主站蜘蛛池模板: 浑源县| 淅川县| 定西市| 浦城县| 武川县| 白玉县| 锡林郭勒盟| 塔河县| 绵阳市| 海晏县| 三河市| 芦溪县| 平武县| 噶尔县| 萨迦县| 海晏县| 开阳县| 云南省| 海口市| 长汀县| 颍上县| 阿鲁科尔沁旗| 菏泽市| 廊坊市| 武宣县| 揭阳市| 克什克腾旗| 通道| 雷州市| 崇文区| 河源市| 和政县| 安庆市| 竹溪县| 丁青县| 赞皇县| 邳州市| 陆河县| 临高县| 江油市| 丹巴县|