0% found this document useful (0 votes)
15 views1 page

Action Event Demo

The document is a Java program that demonstrates the use of ActionEvent and ActionListener interfaces. It creates a simple GUI with two buttons, 'OK' and 'CANCEL', and a label that updates based on which button is pressed. The main method initializes the frame and makes it visible with specified dimensions and title.

Uploaded by

payalmandewad005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Action Event Demo

The document is a Java program that demonstrates the use of ActionEvent and ActionListener interfaces. It creates a simple GUI with two buttons, 'OK' and 'CANCEL', and a label that updates based on which button is pressed. The main method initializes the frame and makes it visible with specified dimensions and title.

Uploaded by

payalmandewad005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//Class: ActionEvent & Interface: ActionListener

import java.awt.*;
import java.awt.event.*;
class ActionEventDemo extends Frame implements ActionListener
{
Button b1,b2;
Label L1;
ActionEventDemo()
{
FlowLayout f1=new FlowLayout();
setLayout(f1);
b1=new Button("OK");
b2=new Button("CANCEL");
L1=new Label(" ");
add(b1);
add(b2);
add(L1);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
//String str=ae.getActionCommand();
//if(str.equals("OK"))
if(ae.getSource()==b1)
{
L1.setText("Ok Button pressed");
}
else
{
L1.setText("Cancel Button pressed");
}
}
public static void main(String args[])
{
ActionEventDemo a1=new ActionEventDemo();
a1.setVisible(true);
a1.setSize(500,500);
a1.setTitle("VJTech Frame");
}
}

You might also like