-2
我有一個簡單的程序,應該接受來自文本字段或按鈕的輸入。Java JButton無響應
但是,該按鈕完全沒有響應。我錯過了明顯的東西嗎?
public class BoxDiagram extends GraphicsProgram {
private static final int MAX_CHARS = 25;
public void init() {
addActionListeners();
nameField = new JTextField(MAX_CHARS);
nameField.addActionListener(this);
addButton = new JButton("Add");
add(nameField, SOUTH);
add(addButton, SOUTH);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == addButton || source == nameField) {
add(new GLabel("hello", getWidth()/2, getHeight()/2));
}
}
private JTextField nameField;
private JButton addButton;
}