Ticket #2306: EventHandler.java

File EventHandler.java, 717 bytes (added by anonymous, 12 years ago)
Line 
1import java.applet.*;
2import java.awt.*;
3import java.awt.event.*;
4
5//<applet code=EventHandler height=100 width=100></applet>
6public class EventHandler extends Applet implements ActionListener
7{
8Button btn1,btn2;
9Label lb;
10public void init()
11{
12//creation of awt components
13btn1=new Button("hello");
14btn2=new Button("good morning");
15lb=new Label("hiii");
16//adding awt components to container
17
18add(btn1);
19add(btn2);
20add(lb);
21//registering components
22btn1.addActionListener(this);
23btn2.addActionListener(this);
24}
25public void actionPerformed(ActionEvent ae)
26{
27if(ae.getSource()==btn1)
28{
29lb.setText("hello");
30}
31if(ae.getSource()==btn2)
32{
33lb.setText("good morning");
34}
35}
36
37
38
39
40
41
42}
43