0% found this document useful (0 votes)
12 views

Java Program Action Event Demo

This Java program demonstrates how to use action events to trigger an action when a button is clicked. It creates a frame with a button, sets the background color to red when the button is clicked by implementing the actionPerformed method, and closes the window when it is closed by implementing the windowClosing method. The main method creates an instance of the ActionEventDemo class to run the program.

Uploaded by

mohit1shukla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Java Program Action Event Demo

This Java program demonstrates how to use action events to trigger an action when a button is clicked. It creates a frame with a button, sets the background color to red when the button is clicked by implementing the actionPerformed method, and closes the window when it is closed by implementing the windowClosing method. The main method creates an instance of the ActionEventDemo class to run the program.

Uploaded by

mohit1shukla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

// JavaProgram Action Event Demo .

import java.awt.*;

import java.awt.event.*;

public class ActionEventDemo extends WindowAdapter implements ActionListener

Frame fr;

Button b1;

ActionEventDemo()

fr=new Frame();

b1=new Button("click");

fr.setLayout(new FlowLayout());

fr.add(b1);

fr.setSize(300,300);

fr.setVisible(true);

fr.addWindowListener(this);

b1.addActionListener(this);//register source with Listener

public void actionPerformed(ActionEvent ae)

{
fr.setBackground(Color.red);

public void windowClosing(WindowEvent e)

System.exit(0);

public static void main(String args[])

ActionEventDemo obj=new ActionEventDemo();

:::::::: Just For Your Help :::::::::


www.Futurez-Downloads.com
www.HostVilla.in
[email protected]

You might also like