Thursday, 16 May 2013

Event Handling Demo by Java

This is the Simplest Program to show the EventHandling by the Java for the Java GUI Components
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package eventdemo;
import java.awt.*;
import java.awt.event.*;

/**
*
* @author Fedora
*/
public class EventDemo implements ActionListener {
Frame f;
Button b;
EventDemo(){
f=new Frame("Title Bar");
b=new Button("Okay");
f.add(b);
b.addActionListener(this);
f.setSize(200,200);
f.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new EventDemo();
}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b){
System.exit(0);
}
}
}


No comments:

Post a Comment