-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonDemoLab1.java
More file actions
45 lines (44 loc) · 992 Bytes
/
Copy pathButtonDemoLab1.java
File metadata and controls
45 lines (44 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code= ButtonDemoLab1 width = 300 height = 300></applet>*/
public class ButtonDemoLab1 extends Applet implements ActionListener
{
Button b1,b2,b3;
String msg = " ";
public void init(){
b1 = new Button("Red");
b2 = new Button("Green");
b3 = new Button("Blue");
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if(s.equals("Red"))
{
setBackground(Color.red);
showStatus("I pressed red Button");
}
else if(s.equals("Green"))
{
setBackground(Color.green);
showStatus("I pressed green Button");
}
else if(s.equals("Blue"))
{
setBackground(Color.blue);
showStatus("I pressed blue Button");
}
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,0,100);
}
}