-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColourChanger.java
More file actions
78 lines (74 loc) · 2.04 KB
/
ColourChanger.java
File metadata and controls
78 lines (74 loc) · 2.04 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ColourChanger extends JFrame implements ActionListener{
JButton daamin, red, blue, green, yellow;
ColourChanger(){
super("Colour Changer");
setSize(300, 220);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane=new JPanel();
daamin=new JButton("Daamin Ashai");
daamin.addActionListener(this);
red=new JButton("Red");
red.setBackground(Color.RED);
red.setOpaque(true);
red.addActionListener(this);
blue=new JButton("Blue");
blue.setBackground(Color.BLUE);
blue.setOpaque(true);
blue.addActionListener(this);
green=new JButton("Green");
green.setBackground(Color.GREEN);
green.setOpaque(true);
green.addActionListener(this);
yellow=new JButton("Yellow");
yellow.setBackground(Color.YELLOW);
yellow.setOpaque(true);
yellow.addActionListener(this);
pane.add(daamin);
pane.add(red);
pane.add(blue);
pane.add(green);
pane.add(yellow);
add(pane);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent evt){
Object source=evt.getSource();
if (source == daamin){
JOptionPane.showMessageDialog(null, "Please press another button", "Error", JOptionPane.ERROR_MESSAGE);
}
else if (source == red){
daamin.setBackground(Color.RED);
daamin.setOpaque(true);
}
else if (source == blue){
daamin.setBackground(Color.BLUE);
daamin.setOpaque(true);
}
else if (source == green){
daamin.setBackground(Color.GREEN);
daamin.setOpaque(true);
}
else if (source == yellow){
daamin.setBackground(Color.YELLOW);
daamin.setOpaque(true);
}
repaint();
}
void setLookAndFeel() {
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
}
catch (Exception exc) {
System.err.println("Couldn't use the system "+"look and feel:"+exc);
}
}
public static void main(String[] args){
ColourChanger cc=new ColourChanger();
cc.setLookAndFeel();
}
}