テキスト フィールドまたはボタンからの入力を受け入れる単純なプログラムがあります。
ただし、ボタンはまったく反応しません。明らかな何かが欠けていますか?
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;
}