JButton ActionListener Example

JButton ActionListener Example

JButton ActionListener Example Note: It is advised to read Java JFC Swing Introduction and Swing Overview before reading this.

Just like AWT button, the Swing JButton also can be given event-handling. The same program of AWT button (of 8 steps) is converted into JButton.

In the following program, as per the JButton clicked, the background of the frame changes. It is advised to read Java AWT Button – Learning GUI – 8 Steps for basic steps involved in creating GUI.

JButton ActionListener Example

import javax.swing.*;
import java.awt.*;
import java.awt.event.* ;


JButton ActionListener Example
Output Screenshot on JButton ActionListener Example

c = getContentPane();
c.setLayout(new FlowLayout());

Read Swing Overview to learn on lightweight and heavyweight components, content pane and Container.

Leave a Reply

Your email address will not be published. Required fields are marked *