EventHandling codes:
The event handling code can put into one of
the following places:
1. same class
2. other class
3. anonymous class
Example of event handling within class
import java.awt.*;
import java.awt.event.*;
class DiamondEvent extends Frame implements
ActionListener{
Textfield tf;
DiamondEvent(){
tf = new TextField();
tf.setBounds(40,50,60,20);
Button b = new Button(“click me”);
b.setBounds(100,120,85,35);
b.addActionListener(this);
add(b);
add(tf);
setSize(300,300);
setLayout(null);
setLayout(true);
}
public void actionPerform(ActionEvent e){
tf.setText(“ you are welcome”);
}
public static void main(String args[]){
new DiamondEvent();
}
}