我是,試圖做一個小應用程序,現在我需要從JTextField
採取一些數據,當我按下某個按鈕。問題是,當我按下按鈕時,沒有任何反應..我用println("yes")
和s working printing "yes' on
ActionListener`測試了它。我該怎麼辦 ?JText .getText()不返回任何內容?
下面是部分代碼:
label = new Label("Width:");
label.setMaximumSize(new Dimension(40, 25));
this.add(label);
textField = new TextField();
textField.setPreferredSize(new Dimension(80, 25));
textField.setMaximumSize(new Dimension(80, 25));
this.add(textField);
button = new JButton("Submit");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(textField.getText()); // <- here textField.getText() does not return anything.
}
});
this.add(button);