我有一个程序将使用JTextField创建一个JFrame。如何让它等待文本在JTextField /按下回车键?
public static void main(String[] args) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int) screenSize.getWidth();
int height = (int) screenSize.getHeight();
JFrame frame = new JFrame();
frame.getContentPane().add(new Text());
JTextField field = new JTextField(10);
frame.add(field, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width,height-55);
frame.setVisible(true);
// There is a keylistener here called listener. It was 100 lines. Did not want to copy
frame.addKeyListener(listener);
double x = 0;
x = Double.parseDouble(field.getText());
System.out.println(x);
我想要
x = Double.parseDouble(field.getText());
仅在有人在JFrame中的JTextField中键入内容时运行。
答案 0 :(得分:3)
例如:
inputType