如何使用附加到按鈕的動作監聽器。我如何使它從一個單獨的類文件中工作?動作監聽器
編輯: 這是我所:
import java.awt.*;
進口java.awt.event中。*;
公共類桂{
static boolean playerturn = true;
public static void main(String[] args) {
Frame frame1 =new Frame("TickTacToe - By Fred");
frame1.setLayout(null);
frame1.setBounds(250,150,500,500);
frame1.setVisible(true);
frame1.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
final Button button11 = new Button("");
button11.addActionListener(null);
final Button button12 = new Button("");
button11.addActionListener(null);
final Button button13 = new Button("");
button11.addActionListener(null);
final Button button21 = new Button("");
button11.addActionListener(null);
final Button button22 = new Button("");
button11.addActionListener(null);
final Button button23 = new Button("");
button11.addActionListener(null);
final Button button31 = new Button("");
button11.addActionListener(null);
final Button button32 = new Button("");
button11.addActionListener(null);
final Button button33 = new Button("");
button11.addActionListener(null);
button11.setBounds(100, 100, 80, 70);
button12.setBounds(100, 200, 80, 70);
button13.setBounds(100, 300, 80, 70);
button21.setBounds(200, 100, 80, 70);
button22.setBounds(200, 200, 80, 70);
button23.setBounds(200, 300, 80, 70);
button31.setBounds(300, 100, 80, 70);
button32.setBounds(300, 200, 80, 70);
button33.setBounds(300, 300, 80, 70);
frame1.add(button11);
frame1.add(button12);
frame1.add(button13);
frame1.add(button21);
frame1.add(button22);
frame1.add(button23);
frame1.add(button31);
frame1.add(button32);
frame1.add(button33);
}}
我需要的是好歹是能夠利用監聽器。
請詳細說明您的具體問題。 –
[你有什麼嘗試?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – user1329572