-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtonColor.java
39 lines (37 loc) · 1.03 KB
/
ButtonColor.java
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonColor implements ActionListener{
JFrame f;
JButton b1,b2,ans;
JLabel l;
ButtonColor()
{
f=new JFrame("COLOR CHANGER");
b1=new JButton("Red");
b2=new JButton("Green");
ans=new JButton("BUTTON");
l=new JLabel("Tap to change color");
f.add(b1);f.add(b2);f.add(ans);f.add(l);
f.setSize(400,350);
f.setLayout(null);
f.setVisible(true);
l.setBounds(100,50,200,20);
b1.setBounds(70,100,100,30);
b2.setBounds(230,100,100,30);
ans.setBounds(150,200,100,30);
b1.addActionListener(this);
b2.addActionListener(this);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
ans.setBackground(Color.red);
else
ans.setBackground(Color.green);
}
public static void main(String[] args) {
new ButtonColor();
}
}