I am doing awt work, but awt is not easy compared with JavaFX I learned before, I am struggling in setting an event for the button in the frame, and I have a PlayAgain() method, my aim is to call the method when the button is clicked. Additional: please do not create an inner class such to implement some Handlers, and justing using awt rather than swing/Fx.
This is my code:
public class CircleDraw extends Frame{
int[] diceResults;
public void paint(Graphics g) {
super.paint(g);
//in this part, I just using Graphics drawing some circles.
}
public void PlayAgain() {
//......do something
}
public static void main(String args[]) {
Frame frame = new CircleDraw();
Button button = new Button("again!");//this is the button, I want to set a Event, when clicking the button,my program will call PlayAgain() method
frame.add(button);
button.setBounds(5, 5, 5, 5);
frame.add(button);
frame.setLayout(new FlowLayout());
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
frame.setSize(500, 250);
frame.setVisible(true);
}
}
I remember in JavaFX it indeed could be written like this:
button.setMouseClicked(e -> {
//call the method} )
So is there something similar in the awt could do this?