package com.vci.rmip.code.client.codeapply.Apply410.swing;
|
|
import com.vci.base.ui.swing.components.NumberPlainDocument;
|
import com.vci.base.ui.swing.components.VCIJTextField;
|
|
import javax.swing.text.Document;
|
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyEvent;
|
|
public class RealTextField extends VCIJTextField {
|
/**
|
*
|
*/
|
private static final long serialVersionUID = -2711989168936034987L;
|
|
/**
|
*
|
*/
|
|
public RealTextField(String text) {
|
super(text);
|
addKeyListener(new KeyAdapter() {
|
public void keyReleased(KeyEvent e) {
|
this_keyReleased(e);
|
}
|
});
|
}
|
|
private void this_keyReleased(KeyEvent e) {
|
String text = getText();
|
if (text.equals(""))
|
return;
|
// 数值不能以-.或.开头
|
if (text.startsWith("-.")) {
|
text = "-0." + text.substring(2);
|
} else if (text.startsWith(".")) {
|
text = "0." + text.substring(1);
|
}
|
String str = text.substring(0, text.length() - 1);
|
String last = text.substring(text.length() - 1);
|
// Real类型的输入时,只能出现一个.
|
if (last.equals(".")) {
|
if (str.indexOf(".") > 0) {
|
text = str;
|
}
|
}
|
setText(text);
|
}
|
|
@Override
|
protected Document createDefaultModel() {
|
return new NumberPlainDocument(true);
|
}
|
}
|