How do I use the action listeners that are attached to the buttons. And how would I make it work from a separate class file?
Edit:
This is what i have:
import java.awt.*;
import java.awt.event.*;
public class Gui {
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);
}}
What i need is someway of being able to utilize the listeners.
Import it, if you need to, and then create an instance of it.
Place the logic that you’d like to be executed within the
actionPerformed(ActionEvent e)method of theActionListenerclass (or subclass).For more information, see How to Write an Action Listener.