forked from ranjansharma255/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonDemo.java
More file actions
57 lines (51 loc) · 1 KB
/
ButtonDemo.java
File metadata and controls
57 lines (51 loc) · 1 KB
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
47
48
49
50
51
52
53
54
55
56
57
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code = "ButtonDemo" width = 500 height = 300>
</applet>
*/
public class ButtonDemo 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 ae)
{
String s = ae.getActionCommand();
if(s.equals("RED"))
{
setBackground(Color.red);
msg = "I pressed on red color";
}
else if(s.equals("GREEN"))
{
setBackground(Color.green);
msg = "I pressed on green color";
}
else
{
if(s.equals("BLUE"))
{
setBackground(Color.blue);
msg = "I pressed on blue color";
}
}
repaint();
}
public void paint (Graphics g)
{
g.drawString(msg,0,100);
}
}