-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorslider.java
82 lines (67 loc) · 2.05 KB
/
colorslider.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
72
73
74
75
76
77
78
79
80
81
82
package mayank;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class colorslider extends JFrame{
private JSlider reds,blues,greens;
private JLabel redl,bluel,greenl;
private JPanel sliders,labels,colorpanel;
public colorslider(){
super("color changer");
reds=new JSlider(JSlider.HORIZONTAL,0,200,0);
blues=new JSlider(JSlider.HORIZONTAL,0,200,0);
greens=new JSlider(JSlider.HORIZONTAL,0,200,0);
redl=new JLabel("red=0");
bluel=new JLabel("blue=0");
greenl=new JLabel("green=0");
colorpanel=new JPanel();
colorpanel.setBackground(Color.BLACK);
labels=new JPanel();
sliders=new JPanel();
Container pane=new Container();
pane=this.getContentPane();
pane.setLayout(new GridLayout(1,3,3,3));
sliders.setLayout(new GridLayout(3, 1));
sliders.add(reds);
sliders.add(greens);
sliders.add(blues);
labels.setLayout(new GridLayout(3,1));
labels.add(redl);
labels.add(greenl);
labels.add(bluel);
reds.addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent e) {
redl.setText(String.format("red=%d", reds.getValue()));
colorpanel.setBackground( new Color(reds.getValue(),greens.getValue(),blues.getValue()));
}
}
);
greens.addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent e) {
greenl.setText(String.format("green=%d", greens.getValue()));
colorpanel.setBackground( new Color(reds.getValue(),greens.getValue(),blues.getValue()));
}
}
);
blues.addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent e) {
bluel.setText(String.format("blue=%d", blues.getValue()));
colorpanel.setBackground( new Color(reds.getValue(),greens.getValue(),blues.getValue()));
}
}
);
pane.add(sliders);
pane.add(labels);
pane.add(colorpanel);
}
public static void main(String[] args) {
colorslider ob=new colorslider();
ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ob.setVisible(true);
ob.setSize(300,200);
}
}