The Artima Developer Community
Sponsored Link

Java Answers Forum
RGB - Color Question: Please Help

3 replies on 1 page. Most recent reply: Dec 24, 2002 5:13 PM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
lee

Posts: 3
Nickname: safc
Registered: Dec, 2002

RGB - Color Question: Please Help Posted: Dec 23, 2002 8:05 AM
Reply to this message Reply
Advertisement
I am looking to create a feature on my Java Applet so you can manually select the color components(RGB) of a background.
I have got as far as:

public Color ( int r, int g, int b )

but on the applet I have 3 separate text boxes(one for red, one for green, one for blue)

so how would I code it so that when the user enters a number for each color component(e.g. 255,0,0) and then a button is pressed that relevant color is produced(red in the example).

Thanks for any help


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: RGB - Color Question: Please Help Posted: Dec 23, 2002 10:08 AM
Reply to this message Reply
Here is your applet. You can run the colorchooser.ColorChooser class as an application also.

package colorchooser;
 
import javax.swing.*;
import java.awt.*;
import javax.swing.event.* ;
 
 
public class ColorChooser extends JApplet {
  JPanel mainPanel = new JPanel();
  JPanel scrollPanels = new JPanel();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  JLabel redLabel = new JLabel();
  JLabel greenLabel = new JLabel();
  JLabel blueLabel = new JLabel();
  JSlider redSlider = new JSlider();
  JSlider greenSlider = new JSlider();
  JSlider blueSlider = new JSlider();
  GridBagLayout gridBagLayout2 = new GridBagLayout();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JLabel redDecimal = new JLabel();
  JLabel greenDecimal = new JLabel();
  JLabel jLabel7 = new JLabel();
  JLabel redHex = new JLabel();
  JLabel greenHex = new JLabel();
  JLabel jLabel10 = new JLabel();
  JLabel redOctal = new JLabel();
  JLabel greenOctal = new JLabel();
  JLabel jLabel13 = new JLabel();
  JLabel blueDecimal = new JLabel();
  JLabel blueHex = new JLabel();
  JLabel blueOctal = new JLabel();
  JLabel colorLabel = new JLabel();
  JLabel jLabel5 = new JLabel();
  public ColorChooser() throws HeadlessException {
  }
  public void init() {
    try {
      jbInit();
      this.redSlider.setValue( 100 ) ;
      this.greenSlider.setValue( 255 ) ;
      this.blueSlider.setValue( 150 ) ;
      this.setDetails();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * sets the color in label and also sets the color values in
   * decimal and hex
   */
  public void setDetails ( ) {
    // Get color values
    int red = this.redSlider.getValue();
    int green = this.greenSlider.getValue();
    int blue = this.blueSlider.getValue();
 
    // Set the decimal values
    this.redDecimal.setText(red + "");
    this.greenDecimal.setText(green + "");
    this.blueDecimal.setText(blue + "");
 
    // In hex
    this.redHex.setText( Integer.toHexString(red) + "");
    this.greenHex.setText(Integer.toHexString(green) + "");
    this.blueHex.setText(Integer.toHexString(blue) + "");
 
    // In Octal
    this.redOctal.setText( Integer.toOctalString(red) + "" ) ;
    this.greenOctal.setText(Integer.toOctalString(green) + "");
    this.blueOctal.setText(Integer.toOctalString(blue) + "");
 
    // In RGB form
 
 
    // set the backgrond color for label
    colorLabel.setBackground(new Color (red, green, blue));
 
  }
  public static void main(String[] args) throws HeadlessException {
    ColorChooser colorChooser1 = new ColorChooser();
    colorChooser1.init();
    JFrame f = new JFrame ("Color Chooser" ) ;
    f.setBounds ( 20, 20 , 400, 400 ) ;
    f.getContentPane().add ( colorChooser1 ) ;
    f.show() ;
  }
  private void jbInit() throws Exception {
    this.getContentPane().setLayout(new BorderLayout());
    mainPanel.setLayout(gridBagLayout2);
    scrollPanels.setLayout(gridBagLayout1);
    scrollPanels.setMinimumSize(new Dimension(300, 300));
    scrollPanels.setPreferredSize(new Dimension(300, 300));
    redLabel.setBackground(Color.red);
    redLabel.setLabelFor(redSlider);
    redLabel.setText("Red:");
    greenLabel.setLabelFor(greenSlider);
    greenLabel.setText("Green:");
    blueLabel.setLabelFor(blueSlider);
    blueLabel.setText("Blue:");
    redSlider.setExtent(1);
    redSlider.setInverted(false);
    redSlider.setMajorTickSpacing(50);
    redSlider.setMaximum(256);
    redSlider.setMinorTickSpacing(1);
    redSlider.setPaintLabels(true);
    redSlider.setPaintTicks(true);
    redSlider.setPaintTrack(true);
    redSlider.setDoubleBuffered(true);
    redSlider.setMinimumSize(new Dimension(300, 32));
    redSlider.setPreferredSize(new Dimension(300, 32));
    redSlider.setToolTipText("");
    redSlider.addChangeListener(new ColorChooser_redSlider_changeAdapter(this));
    blueSlider.setExtent(1);
    blueSlider.setInverted(false);
    blueSlider.setMajorTickSpacing(50);
    blueSlider.setMaximum(256);
    blueSlider.setMinorTickSpacing(1);
    blueSlider.setPaintLabels(true);
    blueSlider.setPaintTicks(true);
    blueSlider.setPaintTrack(true);
    blueSlider.setDoubleBuffered(true);
    blueSlider.setMinimumSize(new Dimension(300, 32));
    blueSlider.setPreferredSize(new Dimension(300, 32));
    blueSlider.setToolTipText("");
    blueSlider.addChangeListener(new ColorChooser_blueSlider_changeAdapter(this));
    greenSlider.setExtent(1);
    greenSlider.setInverted(false);
    greenSlider.setMajorTickSpacing(50);
    greenSlider.setMaximum(256);
    greenSlider.setMinorTickSpacing(1);
    greenSlider.setPaintLabels(true);
    greenSlider.setPaintTicks(true);
    greenSlider.setPaintTrack(true);
    greenSlider.setDoubleBuffered(true);
    greenSlider.setMinimumSize(new Dimension(300, 32));
    greenSlider.setPreferredSize(new Dimension(300, 32));
    greenSlider.setToolTipText("");
    greenSlider.addChangeListener(new ColorChooser_greenSlider_changeAdapter(this));
    mainPanel.setMinimumSize(new Dimension(100, 100));
    mainPanel.setPreferredSize(new Dimension(100, 100));
    jLabel1.setFont(new java.awt.Font("SansSerif", 1, 11));
    jLabel1.setText("Color");
    jLabel2.setFont(new java.awt.Font("SansSerif", 0, 11));
    jLabel2.setText("Red:");
    jLabel3.setFont(new java.awt.Font("SansSerif", 0, 11));
    jLabel3.setText("Green:");
    jLabel4.setFont(new java.awt.Font("SansSerif", 1, 11));
    jLabel4.setText("Decimal");
    redDecimal.setFont(new java.awt.Font("SansSerif", 0, 11));
    redDecimal.setText("jLabel5");
    greenDecimal.setFont(new java.awt.Font("Dialog", 0, 11));
    greenDecimal.setText("jLabel6");
    jLabel7.setFont(new java.awt.Font("SansSerif", 1, 11));
    jLabel7.setText("Hex");
    redHex.setFont(new java.awt.Font("Dialog", 0, 11));
    redHex.setText("jLabel8");
    greenHex.setFont(new java.awt.Font("Dialog", 0, 11));
    greenHex.setText("jLabel9");
    jLabel10.setFont(new java.awt.Font("SansSerif", 1, 11));
    jLabel10.setText("Octal");
    redOctal.setFont(new java.awt.Font("Dialog", 0, 11));
    redOctal.setText("jLabel11");
    greenOctal.setFont(new java.awt.Font("Dialog", 0, 11));
    greenOctal.setText("jLabel12");
    jLabel13.setFont(new java.awt.Font("SansSerif", 0, 11));
    jLabel13.setText("Blue:");
    blueDecimal.setFont(new java.awt.Font("Dialog", 0, 11));
    blueDecimal.setText("jLabel14");
    blueHex.setFont(new java.awt.Font("Dialog", 0, 11));
    blueHex.setText("jLabel15");
    blueOctal.setFont(new java.awt.Font("Dialog", 0, 11));
    blueOctal.setText("jLabel16");
    colorLabel.setBackground(Color.pink);
    colorLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
    colorLabel.setForeground(Color.black);
    colorLabel.setMinimumSize(new Dimension(100, 20));
    colorLabel.setOpaque(true);
    colorLabel.setPreferredSize(new Dimension(100, 20));
    colorLabel.setText("");
    jLabel5.setText("Color:");
    this.getContentPane().add(mainPanel, BorderLayout.NORTH);
    mainPanel.add(jLabel1,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel2,   new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel3,   new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel4,  new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(redDecimal,  new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(greenDecimal,  new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel7,  new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(redHex,  new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(greenHex,  new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel10,  new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(redOctal,  new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(greenOctal,  new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel13,   new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(blueDecimal,  new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(blueHex,  new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(blueOctal,  new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    this.getContentPane().add(scrollPanels, BorderLayout.CENTER);
    scrollPanels.add(greenLabel,                       new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 5, 5));
    scrollPanels.add(blueLabel,                       new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 5, 5));
    scrollPanels.add(redSlider,                   new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 5, 15));
    scrollPanels.add(greenSlider,                    new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 5, 15));
    scrollPanels.add(redLabel,           new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 5, 5));
    scrollPanels.add(jLabel5,          new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    scrollPanels.add(colorLabel,                                       new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 5, 15));
    scrollPanels.add(blueSlider,             new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 5, 15));
    }
 
  void redSlider_stateChanged(ChangeEvent e) {
    this.setDetails();
  }
 
  void greenSlider_stateChanged(ChangeEvent e) {
    this.setDetails();
  }
 
  void blueSlider_stateChanged(ChangeEvent e) {
    this.setDetails();
  }
 
}
 
class ColorChooser_redSlider_changeAdapter implements javax.swing.event.ChangeListener {
  ColorChooser adaptee;
 
  ColorChooser_redSlider_changeAdapter(ColorChooser adaptee) {
    this.adaptee = adaptee;
  }
  public void stateChanged(ChangeEvent e) {
    adaptee.redSlider_stateChanged(e);
  }
}
 
class ColorChooser_greenSlider_changeAdapter implements javax.swing.event.ChangeListener {
  ColorChooser adaptee;
 
  ColorChooser_greenSlider_changeAdapter(ColorChooser adaptee) {
    this.adaptee = adaptee;
  }
  public void stateChanged(ChangeEvent e) {
    adaptee.greenSlider_stateChanged(e);
  }
}
 
class ColorChooser_blueSlider_changeAdapter implements javax.swing.event.ChangeListener {
  ColorChooser adaptee;
 
  ColorChooser_blueSlider_changeAdapter(ColorChooser adaptee) {
    this.adaptee = adaptee;
  }
  public void stateChanged(ChangeEvent e) {
    adaptee.blueSlider_stateChanged(e);
  }
}

lee

Posts: 3
Nickname: safc
Registered: Dec, 2002

Re: RGB - Color Question: Please Help Posted: Dec 24, 2002 5:21 AM
Reply to this message Reply
Thanks for that! -

But could you tell me why it says :

"com.borland.jbuilder.cmt.CmtParseException: Class 'Color' not found"

when I try to run the applet?

===========================================================
This code brings up the sliders. I would also like code which creates an applet that allows to enter the 3 RGB Values required by the user into 3 seperate textboxes e.g. 0,255,0 for GREEN.

Thanks for your help

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: RGB - Color Question: Please Help Posted: Dec 24, 2002 5:13 PM
Reply to this message Reply
I think you were trying to open the java code in JBuilder design window and you had missed some content. You get "com.borland.jbuilder.cmt.CmtParseException" error message in JBuilder when JBuilder is not able to parse the source code successfully. Try copying and pasting the code again and it will work. Following is the code where you have to enter rgb values in text fields. I have just changed the previous code using sliders to text fields.
package colorchooser;
 
import javax.swing.*;
import java.awt.*;
import javax.swing.event.* ;
import java.awt.event.*;
 
public class CCApplet extends JApplet {
  private final static int RED = 0;
  private final static int GREEN = 1;
  private final static int BLUE = 2;
  JPanel mainPanel = new JPanel();
  JPanel scrollPanels = new JPanel();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  JLabel redLabel = new JLabel();
  JLabel greenLabel = new JLabel();
  JLabel blueLabel = new JLabel();
  GridBagLayout gridBagLayout2 = new GridBagLayout();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JLabel redDecimal = new JLabel();
  JLabel greenDecimal = new JLabel();
  JLabel jLabel7 = new JLabel();
  JLabel redHex = new JLabel();
  JLabel greenHex = new JLabel();
  JLabel jLabel10 = new JLabel();
  JLabel redOctal = new JLabel();
  JLabel greenOctal = new JLabel();
  JLabel jLabel13 = new JLabel();
  JLabel blueDecimal = new JLabel();
  JLabel blueHex = new JLabel();
  JLabel blueOctal = new JLabel();
  JLabel colorLabel = new JLabel();
  JLabel jLabel5 = new JLabel();
  JTextField redValue = new JTextField();
  JTextField greenValue = new JTextField();
  JTextField blueValue = new JTextField();
  public CCApplet() throws HeadlessException {
  }
  public void init() {
    try {
      jbInit();
      this.setDetails();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * sets the color in label and also sets the color values in
   * decimal and hex
   */
  public void setDetails ( ) {
    // Get color values
    try {
      int red = this.getColorValue(RED);
      int green = this.getColorValue(GREEN);
      int blue = this.getColorValue(BLUE);
 
      // Set the decimal values
      this.redDecimal.setText(red + "");
      this.greenDecimal.setText(green + "");
      this.blueDecimal.setText(blue + "");
 
      // In hex
      this.redHex.setText(Integer.toHexString(red) + "");
      this.greenHex.setText(Integer.toHexString(green) + "");
      this.blueHex.setText(Integer.toHexString(blue) + "");
 
      // In Octal
      this.redOctal.setText(Integer.toOctalString(red) + "");
      this.greenOctal.setText(Integer.toOctalString(green) + "");
      this.blueOctal.setText(Integer.toOctalString(blue) + "");
 
      // In RGB form
 
      // set the backgrond color for label
      colorLabel.setBackground(new Color(red, green, blue));
    }
    catch (Exception e ) {
      JOptionPane.showMessageDialog(this, e.getMessage(),
                                    "Error",
                                    JOptionPane.ERROR_MESSAGE);
    }
 
  }
 
  public int getColorValue ( int color ) {
    String colorName = "";
    JTextField tf ;
 
    switch ( color ) {
      case RED:
        tf = this.redValue;
        colorName = "red";
        break;
      case GREEN:
        tf = this.greenValue;
        colorName = "green";
        break;
      case BLUE:
       tf = this.blueValue;
       colorName = "blue";
       break;
       default:
         throw new RuntimeException ( "Color name must be red, green or blue" );
    }
    // Get the value entered bu user
    String value = tf.getText();
 
    if ( value == null || value.trim().equals("") ) {
      value = "0" ;
    }
    // Try to parse the value
    int intValue = 0 ;
    try {
      intValue = Integer.parseInt(value);
    }
    catch ( Exception e ) {
      tf.requestFocus();
      throw new RuntimeException ( colorName + " value must be an integer" ) ;
    }
 
    // Check the range
    if ( intValue < 0 || intValue > 255 ) {
      tf.requestFocus();
      throw new RuntimeException ( colorName + " value must be between 0-255" ) ;
    }
 
    return intValue;
  }
 
  public static void main(String[] args) throws HeadlessException {
    CCApplet colorChooser1 = new CCApplet();
    colorChooser1.init();
    JFrame f = new JFrame ("Color Chooser" ) ;
    f.setBounds ( 20, 20 , 400, 400 ) ;
    f.getContentPane().add ( colorChooser1 ) ;
    f.show() ;
  }
  private void jbInit() throws Exception {
    this.getContentPane().setLayout(new BorderLayout());
    mainPanel.setLayout(gridBagLayout2);
    scrollPanels.setLayout(gridBagLayout1);
    scrollPanels.setMinimumSize(new Dimension(300, 300));
    scrollPanels.setPreferredSize(new Dimension(300, 300));
    redLabel.setBackground(Color.red);
    redLabel.setText("Red:");
    greenLabel.setText("Green:");
    blueLabel.setText("Blue:");
    mainPanel.setMinimumSize(new Dimension(100, 100));
    mainPanel.setPreferredSize(new Dimension(100, 100));
    jLabel1.setFont(new java.awt.Font("SansSerif", 1, 11));
    jLabel1.setText("Color");
    jLabel2.setFont(new java.awt.Font("SansSerif", 0, 11));
    jLabel2.setText("Red:");
    jLabel3.setFont(new java.awt.Font("SansSerif", 0, 11));
    jLabel3.setText("Green:");
    jLabel4.setFont(new java.awt.Font("SansSerif", 1, 11));
    jLabel4.setText("Decimal");
    redDecimal.setFont(new java.awt.Font("SansSerif", 0, 11));
    redDecimal.setText("jLabel5");
    greenDecimal.setFont(new java.awt.Font("Dialog", 0, 11));
    greenDecimal.setText("jLabel6");
    jLabel7.setFont(new java.awt.Font("SansSerif", 1, 11));
    jLabel7.setText("Hex");
    redHex.setFont(new java.awt.Font("Dialog", 0, 11));
    redHex.setText("jLabel8");
    greenHex.setFont(new java.awt.Font("Dialog", 0, 11));
    greenHex.setText("jLabel9");
    jLabel10.setFont(new java.awt.Font("SansSerif", 1, 11));
    jLabel10.setText("Octal");
    redOctal.setFont(new java.awt.Font("Dialog", 0, 11));
    redOctal.setText("jLabel11");
    greenOctal.setFont(new java.awt.Font("Dialog", 0, 11));
    greenOctal.setText("jLabel12");
    jLabel13.setFont(new java.awt.Font("SansSerif", 0, 11));
    jLabel13.setText("Blue:");
    blueDecimal.setFont(new java.awt.Font("Dialog", 0, 11));
    blueDecimal.setText("jLabel14");
    blueHex.setFont(new java.awt.Font("Dialog", 0, 11));
    blueHex.setText("jLabel15");
    blueOctal.setFont(new java.awt.Font("Dialog", 0, 11));
    blueOctal.setText("jLabel16");
    colorLabel.setBackground(Color.pink);
    colorLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
    colorLabel.setForeground(Color.black);
    colorLabel.setMinimumSize(new Dimension(100, 20));
    colorLabel.setOpaque(true);
    colorLabel.setPreferredSize(new Dimension(100, 20));
    colorLabel.setText("");
    jLabel5.setText("Color:");
    redValue.setMinimumSize(new Dimension(60, 21));
    redValue.setPreferredSize(new Dimension(60, 21));
    redValue.setText("100");
    redValue.addKeyListener(new CCApplet_redValue_keyAdapter(this));
    greenValue.setMinimumSize(new Dimension(60, 21));
    greenValue.setPreferredSize(new Dimension(60, 21));
    greenValue.setText("150");
    greenValue.addKeyListener(new CCApplet_greenValue_keyAdapter(this));
    blueValue.setMinimumSize(new Dimension(60, 21));
    blueValue.setPreferredSize(new Dimension(60, 21));
    blueValue.setText("255");
    blueValue.addKeyListener(new CCApplet_blueValue_keyAdapter(this));
    this.getContentPane().add(mainPanel, BorderLayout.NORTH);
    mainPanel.add(jLabel1,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel2,   new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel3,   new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel4,  new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(redDecimal,  new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(greenDecimal,  new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel7,  new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(redHex,  new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(greenHex,  new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel10,  new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(redOctal,  new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(greenOctal,  new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(jLabel13,   new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(blueDecimal,  new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(blueHex,  new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    mainPanel.add(blueOctal,  new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0));
    this.getContentPane().add(scrollPanels, BorderLayout.SOUTH);
    scrollPanels.add(greenLabel,                        new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 5, 5));
    scrollPanels.add(blueLabel,                        new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 5, 5));
    scrollPanels.add(redLabel,            new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 5, 5));
    scrollPanels.add(jLabel5,           new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    scrollPanels.add(redValue,       new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 37, 0));
    scrollPanels.add(greenValue,      new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 34, 0));
    scrollPanels.add(blueValue,      new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 33, 0));
    scrollPanels.add(colorLabel,         new GridBagConstraints(1, 0, 4, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 147, 15));
    }
 
 
 
  void redValue_keyReleased(KeyEvent e) {
    this.setDetails();
  }
 
  void greenValue_keyReleased(KeyEvent e) {
    this.setDetails();
  }
 
  void blueValue_keyReleased(KeyEvent e) {
    this.setDetails();
  }
 
}
 
 
class CCApplet_redValue_keyAdapter extends java.awt.event.KeyAdapter {
  CCApplet adaptee;
 
  CCApplet_redValue_keyAdapter(CCApplet adaptee) {
    this.adaptee = adaptee;
  }
  public void keyReleased(KeyEvent e) {
    adaptee.redValue_keyReleased(e);
  }
}
 
class CCApplet_greenValue_keyAdapter extends java.awt.event.KeyAdapter {
  CCApplet adaptee;
 
  CCApplet_greenValue_keyAdapter(CCApplet adaptee) {
    this.adaptee = adaptee;
  }
  public void keyReleased(KeyEvent e) {
    adaptee.greenValue_keyReleased(e);
  }
}
 
class CCApplet_blueValue_keyAdapter extends java.awt.event.KeyAdapter {
  CCApplet adaptee;
 
  CCApplet_blueValue_keyAdapter(CCApplet adaptee) {
    this.adaptee = adaptee;
  }
  public void keyReleased(KeyEvent e) {
    adaptee.blueValue_keyReleased(e);
  }
}
 

Flat View: This topic has 3 replies on 1 page
Topic: Connect mySQL by using JDBC in linux Previous Topic   Next Topic Topic: Writing to files

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use