forked from ranjansharma255/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonDemoLab.java
More file actions
46 lines (45 loc) · 998 Bytes
/
ButtonDemoLab.java
File metadata and controls
46 lines (45 loc) · 998 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
46
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code = ButtonDemoLab width = 300 height = 300 > </applet>*/
public class ButtonDemoLab 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("BLUE"))
{
setBackground(Color.blue);
showStatus("I pressed blue button");
}
else if(s.equals("GREEN"))
{
setBackground(Color.green);
showStatus("I pressed green button");
}
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,0,100);
}
}