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