今回はJava in the Boxでおなじみの櫻庭さんからの出題です。
ボタンを押すとどうなる?
次のプログラムを実行して、表示されるボタンを押して、なが〜い処理をしている間、ウインドウの表示はどのようになるでしょうか?
public class Monologue implements ActionListener {
private JButton button = new JButton("実行");
public Monologue() {
JFrame frame = new JFrame("Monologue");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button.addActionListener(this);
button.setPreferredSize(new Dimension(100, 26));
frame.add(button);
frame.setSize(100, 70);
frame.setLayout(new FlowLayout(FlowLayout.CENTER));
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
button.setText("処理中...");
button.setEnabled(false);
// なが〜い処理 ^^;;
button.setText("実行");
button.setEnabled(true);
}
public static void main(String[] args) {
new Monologue();
}
}
そのときウインドウの表示がどのようになっているかを次の中からお選びください。