001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package examples.colorpicker;
043:
044: public class ColorPicker extends javax.swing.JFrame {
045:
046: /** Initializes the Form */
047: public ColorPicker() {
048: initComponents();
049: pack();
050:
051: }
052:
053: /** This method is called from within the constructor to
054: * initialize the form.
055: * WARNING: Do NOT modify this code. The content of this method is
056: * always regenerated by the FormEditor.
057: */
058: private void initComponents() {//GEN-BEGIN:initComponents
059: colorPreviewPanel = new javax.swing.JPanel();
060: colorPreview1 = new examples.colorpicker.ColorPreview();
061: jPanel1 = new javax.swing.JPanel();
062: redSlider = new javax.swing.JSlider();
063: greenSlider = new javax.swing.JSlider();
064: blueSlider = new javax.swing.JSlider();
065:
066: addWindowListener(new java.awt.event.WindowAdapter() {
067: public void windowClosing(java.awt.event.WindowEvent evt) {
068: exitForm(evt);
069: }
070: });
071:
072: colorPreviewPanel.setLayout(new java.awt.BorderLayout());
073:
074: colorPreviewPanel
075: .setBorder(new javax.swing.border.TitledBorder(
076: new javax.swing.border.EtchedBorder(null,
077: new java.awt.Color(134, 134, 134)),
078: "Color Preview",
079: javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
080: javax.swing.border.TitledBorder.DEFAULT_POSITION,
081: new java.awt.Font("Dialog", 0, 11),
082: java.awt.Color.black));
083: colorPreviewPanel.add(colorPreview1,
084: java.awt.BorderLayout.CENTER);
085:
086: getContentPane().add(colorPreviewPanel,
087: java.awt.BorderLayout.CENTER);
088:
089: jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1,
090: javax.swing.BoxLayout.Y_AXIS));
091:
092: redSlider.setMaximum(255);
093: redSlider.setBorder(new javax.swing.border.TitledBorder(
094: new javax.swing.border.EtchedBorder(null,
095: new java.awt.Color(134, 134, 134)), "Red",
096: javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
097: javax.swing.border.TitledBorder.DEFAULT_POSITION,
098: new java.awt.Font("Dialog", 0, 11),
099: java.awt.Color.black));
100: redSlider
101: .addChangeListener(new javax.swing.event.ChangeListener() {
102: public void stateChanged(
103: javax.swing.event.ChangeEvent evt) {
104: redSliderStateChanged(evt);
105: }
106: });
107:
108: jPanel1.add(redSlider);
109:
110: greenSlider.setMaximum(255);
111: greenSlider.setBorder(new javax.swing.border.TitledBorder(
112: new javax.swing.border.EtchedBorder(null,
113: new java.awt.Color(134, 134, 134)), "Green",
114: javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
115: javax.swing.border.TitledBorder.DEFAULT_POSITION,
116: new java.awt.Font("Dialog", 0, 11),
117: java.awt.Color.black));
118: greenSlider
119: .addChangeListener(new javax.swing.event.ChangeListener() {
120: public void stateChanged(
121: javax.swing.event.ChangeEvent evt) {
122: greenSliderStateChanged(evt);
123: }
124: });
125:
126: jPanel1.add(greenSlider);
127:
128: blueSlider.setMaximum(255);
129: blueSlider.setBorder(new javax.swing.border.TitledBorder(
130: new javax.swing.border.EtchedBorder(null,
131: new java.awt.Color(134, 134, 134)), "Blue",
132: javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
133: javax.swing.border.TitledBorder.DEFAULT_POSITION,
134: new java.awt.Font("Dialog", 0, 11),
135: java.awt.Color.black));
136: blueSlider
137: .addChangeListener(new javax.swing.event.ChangeListener() {
138: public void stateChanged(
139: javax.swing.event.ChangeEvent evt) {
140: blueSliderStateChanged(evt);
141: }
142: });
143:
144: jPanel1.add(blueSlider);
145:
146: getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
147:
148: }//GEN-END:initComponents
149:
150: private void blueSliderStateChanged(
151: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_blueSliderStateChanged
152: colorPreview1.setBlue(blueSlider.getValue());
153: }//GEN-LAST:event_blueSliderStateChanged
154:
155: private void greenSliderStateChanged(
156: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_greenSliderStateChanged
157: colorPreview1.setGreen(greenSlider.getValue());
158: }//GEN-LAST:event_greenSliderStateChanged
159:
160: private void redSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_redSliderStateChanged
161: colorPreview1.setRed(redSlider.getValue());
162: }//GEN-LAST:event_redSliderStateChanged
163:
164: /** Exit the Application */
165: private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
166: System.exit(0);
167: }//GEN-LAST:event_exitForm
168:
169: // Variables declaration - do not modify//GEN-BEGIN:variables
170: private examples.colorpicker.ColorPreview colorPreview1;
171: private javax.swing.JPanel colorPreviewPanel;
172: private javax.swing.JSlider greenSlider;
173: private javax.swing.JSlider redSlider;
174: private javax.swing.JPanel jPanel1;
175: private javax.swing.JSlider blueSlider;
176:
177: // End of variables declaration//GEN-END:variables
178:
179: public static void main(java.lang.String[] args) {
180: new ColorPicker().show();
181: }
182:
183: }
|