/*
 * ColorChooser.java
 *
 * Created on December 2, 2006, 9:25 AM
 */

/**
 *
 * @author  paul
 */
public class ColorChooser extends javax.swing.JFrame
{
   
   /** Creates new form ColorChooser */
   public ColorChooser()
   {
      initComponents();
      colorJPanel.setBackground( java.awt.Color.BLACK );
   }
   
   // changes the colorJPanel's background color based on the current
   // values of the JSliders
   public void changeColor()
   {
      colorJPanel.setBackground( new java.awt.Color( 
         redJSlider.getValue(), greenJSlider.getValue(), 
         blueJSlider.getValue() ) );
   } // end method changeColor
   
   /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
   // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
   private void initComponents()
   {
      redJSlider = new javax.swing.JSlider();
      greenJSlider = new javax.swing.JSlider();
      blueJSlider = new javax.swing.JSlider();
      redJLabel = new javax.swing.JLabel();
      greenJLabel = new javax.swing.JLabel();
      blueJLabel = new javax.swing.JLabel();
      redJTextField = new javax.swing.JTextField();
      greenJTextField = new javax.swing.JTextField();
      blueJTextField = new javax.swing.JTextField();
      colorJPanel = new javax.swing.JPanel();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      redJSlider.setMaximum(255);
      redJSlider.setValue(0);
      redJSlider.addChangeListener(new javax.swing.event.ChangeListener()
      {
         public void stateChanged(javax.swing.event.ChangeEvent evt)
         {
            redJSliderStateChanged(evt);
         }
      });

      greenJSlider.setMaximum(255);
      greenJSlider.setValue(0);
      greenJSlider.addChangeListener(new javax.swing.event.ChangeListener()
      {
         public void stateChanged(javax.swing.event.ChangeEvent evt)
         {
            greenJSliderStateChanged(evt);
         }
      });

      blueJSlider.setMaximum(255);
      blueJSlider.setValue(0);
      blueJSlider.addChangeListener(new javax.swing.event.ChangeListener()
      {
         public void stateChanged(javax.swing.event.ChangeEvent evt)
         {
            blueJSliderStateChanged(evt);
         }
      });

      redJLabel.setText("Red:");

      greenJLabel.setText("Green:");

      blueJLabel.setText("Blue:");

      redJTextField.setColumns(4);
      redJTextField.setText("0");

      greenJTextField.setColumns(4);
      greenJTextField.setText("0");

      blueJTextField.setColumns(4);
      blueJTextField.setText("0");

      javax.swing.GroupLayout colorJPanelLayout = new javax.swing.GroupLayout(colorJPanel);
      colorJPanel.setLayout(colorJPanelLayout);
      colorJPanelLayout.setHorizontalGroup(
         colorJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGap(0, 100, Short.MAX_VALUE)
      );
      colorJPanelLayout.setVerticalGroup(
         colorJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGap(0, 100, Short.MAX_VALUE)
      );

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(greenJLabel)
               .addComponent(blueJLabel)
               .addComponent(redJLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                  .addComponent(blueJSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(blueJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGroup(layout.createSequentialGroup()
                  .addComponent(greenJSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(greenJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGroup(layout.createSequentialGroup()
                  .addComponent(redJSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(redJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
            .addComponent(colorJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(colorJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addGroup(layout.createSequentialGroup()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(redJSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(redJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(redJLabel))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(greenJLabel)
                           .addComponent(greenJSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(blueJLabel)
                           .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                              .addComponent(blueJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addComponent(blueJSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                     .addComponent(greenJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );
      pack();
   }// </editor-fold>//GEN-END:initComponents

   private void blueJSliderStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_blueJSliderStateChanged
   {//GEN-HEADEREND:event_blueJSliderStateChanged
      blueJTextField.setText( "" + blueJSlider.getValue() );
      changeColor();
   }//GEN-LAST:event_blueJSliderStateChanged

   private void greenJSliderStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_greenJSliderStateChanged
   {//GEN-HEADEREND:event_greenJSliderStateChanged
      greenJTextField.setText( "" + greenJSlider.getValue() );
      changeColor();
   }//GEN-LAST:event_greenJSliderStateChanged

   private void redJSliderStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_redJSliderStateChanged
   {//GEN-HEADEREND:event_redJSliderStateChanged
      redJTextField.setText( "" + redJSlider.getValue() );
      changeColor();
   }//GEN-LAST:event_redJSliderStateChanged
   
   /**
    * @param args the command line arguments
    */
   public static void main(String args[])
   {
      java.awt.EventQueue.invokeLater(new Runnable()
      {
         public void run()
         {
            new ColorChooser().setVisible(true);
         }
      });
   }
   
   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JLabel blueJLabel;
   private javax.swing.JSlider blueJSlider;
   private javax.swing.JTextField blueJTextField;
   private javax.swing.JPanel colorJPanel;
   private javax.swing.JLabel greenJLabel;
   private javax.swing.JSlider greenJSlider;
   private javax.swing.JTextField greenJTextField;
   private javax.swing.JLabel redJLabel;
   private javax.swing.JSlider redJSlider;
   private javax.swing.JTextField redJTextField;
   // End of variables declaration//GEN-END:variables
   
}


/**************************************************************************
 * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/