posts - 38,  comments - 22,  trackbacks - 0

           /**
            *
            * @param value 要四舍五入的值
            * @param scale 小數(shù)點(diǎn)后要取的位數(shù)
            * @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 閱讀(633) 評(píng)論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 澄城县| 河源市| 陕西省| 汾阳市| 多伦县| 德昌县| 梨树县| 祁阳县| 滨州市| 林周县| 巫溪县| 云梦县| 庆元县| 孝感市| 罗山县| 临朐县| 仙游县| 灌南县| 鄂伦春自治旗| 永康市| 宣化县| 龙里县| 化德县| 凌云县| 镇巴县| 卫辉市| 玉林市| 舒兰市| 开原市| 山东省| 镇康县| 大同县| 湖州市| 岑溪市| 大方县| 奉节县| 平利县| 邻水| 承德市| 平定县| 岳普湖县|