Java-Swing:Introduction to Swing - Introduction to JButton
A JButton is a widget representing something you can click. It can have text describing its purpose, or an icon. You add a listener object (or more) to a button. The listener object represents the action to take when the button is clicked by the user.
By separating the code for the action from the button, we maintain separation of concerns, and we'll get cleaner code.
When the button is clicked, the GUI system makes sure a certain method is called on the listener object. The method is defined in the interface type of the listener, the ActionListener interface, and the listener object is an object implementing that interface and the only required method
public void actionPerformed(ActionEvent ae).
- Introduction to JButton Swing - JButton
- Source code: Github: java-extra-lectures/tree/master/swing/components-examples/jbutton