ptg7068951
226 HOUR 16:Building a Complex User Interface
67: setVisible(true);
68: }
69:
70: public voidstateChanged(ChangeEvent event) {
71: JSlider source = (JSlider) event.getSource();
72: if (source.getValueIsAdjusting() != true) {
73: Color current = new Color(red.getValue(),
➥green.getValue(),
74: blue.getValue());
75: canvas.changeColor(current);
76: canvas.repaint();
77: }
78: }
79:
80: publicInsets getInsets() {
81: Insets border = new Insets(45, 10, 10, 10);
82: returnborder;
83: }
84:
85: private voidsetLookAndFeel() {
86: try {
87: UIManager.setLookAndFeel(
88: “com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”
89: );
90: } catch (Exception exc) {
91: // ignore error
92: }
93: }
94:
95: public static voidmain(String[] arguments) {
96: ColorSliders cs = new ColorSliders();
97: }
98: }
99:
100: classColorPanel extendsJPanel {
101: Color background;
102:
103: ColorPanel() {
104: background= Color.red;
105: }
106:
107: public voidpaintComponent(Graphics comp) {
108: Graphics2D comp2D = (Graphics2D) comp;
109: comp2D.setColor(background);
110: comp2D.fillRect(0, 0, getSize().width, getSize().height);
111: }
112:
113: voidchangeColor(Color newBackground) {
114: background= newBackground;
115: }
116: }
LISTING 16.2 Continued