-
Notifications
You must be signed in to change notification settings - Fork 1
/
ColorPalette.java
71 lines (54 loc) · 1.79 KB
/
ColorPalette.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
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
import java.awt.Color;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class ColorPalette implements ChangeListener{
JFrame window;
JColorChooser cc;
JPanel colorChooserPanel, colorPanel;
JPanel panel = new JPanel();
JLabel textfield = new JLabel();
public static void main(String[] args) {
new ColorPalette();
}
public ColorPalette() {
window = new JFrame();
window.setSize(800, 700);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setBackground(new Color(255, 250, 250));
window.setLayout(null);
panel.setBackground(new Color(198, 226,255));
panel.setBounds(50,50,700,570);
window.add(panel);
colorChooserPanel = new JPanel();
colorChooserPanel.setBounds(100,50,600,300);
colorChooserPanel.setBackground(new Color(198,226,255));
panel.add(colorChooserPanel);
cc = new JColorChooser();
cc.getSelectionModel().addChangeListener(this);
// You can remove the color palette by typing code here! (Codes are in the README.)
cc.setPreviewPanel(new JPanel());
colorChooserPanel.add(cc);
cc.setBackground(new Color(198,226,255));
colorPanel = new JPanel();
colorPanel.setBounds(100,400,600,170);
colorPanel.setBackground(Color.yellow);
window.add(colorPanel);
textfield.setText("Output; ");
textfield.setFont(new Font("Serif",Font.BOLD, 25));
textfield.setForeground(Color.white);
textfield.setBounds(100,400,600,170);
panel.add(textfield);
window.setVisible(true);
}
public void stateChanged(ChangeEvent e) {
Color newColor = cc.getColor();
colorPanel.setBackground(newColor);
}
}