-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaColorChooser.java
More file actions
55 lines (46 loc) · 1.35 KB
/
JavaColorChooser.java
File metadata and controls
55 lines (46 loc) · 1.35 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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner ;
//Archived By Shadow Corps
@SuppressWarnings("serial")
public class JColorChooserDemo extends JFrame
{
JPanel panel;
Color bgColor = Color.LIGHT_GRAY;
public JColorChooserDemo()
{
panel = new JPanel(new BorderLayout());
JButton btnColor = new JButton("Change Color");
panel.add(btnColor, BorderLayout.SOUTH);
btnColor.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent evt)
{
Color color = JColorChooser.showDialog(JColorChooserDemo.this,
"Choose a color", bgColor);
if (color != null) {
bgColor = color;
}
panel.setBackground(bgColor);
}
});
setContentPane(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("JColorChooser Demo");
setSize(300, 200);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run() {
new JColorChooserDemo();
}
});
}
}