DecimalField.java
上传用户:xiekaiwei
上传日期:2015-07-04
资源大小:620k
文件大小:1k
- package org.tn5250j.tools;
- import javax.swing.*;
- 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));
- }
- }