⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decimalfield.java

📁 java图形用户界面 6.1 HelloWorldSwing 6.2 按钮计数器 6.3 Swing按钮 6.4 温度转换器 6.5 HtmlDemo 6.6 投票器 6.7 TextS
💻 JAVA
字号:
import javax.swing.*; import javax.swing.text.*; import java.awt.Toolkit;import java.text.*;public class DecimalField extends JTextField {    private NumberFormat format;    public DecimalField(double value, int columns, NumberFormat f) {        super(columns);        setDocument(new FormattedDocument(f));        format = f;        setValue(value);    }    public double getValue() {        double retVal = 0.0;        try {            retVal = format.parse(getText()).doubleValue();        } catch (ParseException e) {            // This should never happen because insertString allows            // only properly formatted data to get in the field.            Toolkit.getDefaultToolkit().beep();            System.err.println("getValue: could not parse: " + getText());        }        return retVal;    }    public void setValue(double value) {        setText(format.format(value));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -