forked from VenusTokyo/first-year-java-practicals
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonColor.java
More file actions
44 lines (36 loc) · 872 Bytes
/
ButtonColor.java
File metadata and controls
44 lines (36 loc) · 872 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
import java.awt.*;
import java.awt.event.*;
public class ButtonColor extends Frame implements ActionListener
{
Button redb, blueb;
public ButtonColor()
{
FlowLayout fl = new FlowLayout();
setLayout(fl);
redb = new Button("Red");
blueb = new Button("Blue");
redb.addActionListener(this);
blueb.addActionListener(this);
add(redb);
add(blueb);
setTitle("Button in Action");
setSize(300, 350);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
System.out.println("You clicked " + str + " button");
if(str.equals("Red"))
{
setBackground(Color.red);
}
else if(str.equals("Blue"))
{
setBackground(Color.blue);
}
}
public static void main(String args[])
{
new ButtonColor();
}
}