Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

Color pick...

On a panel/ frame, I want to build three sliders for three colors Red, Green, and Blue to pick and their resultant color to be displayed on another panel next to it.

Question: Where to start?
0
Mike Eghtebas
Asked:
Mike Eghtebas
1 Solution
 
Amitkumar PSr. ConsultantCommented:
0
 
CEHJCommented:
Start here http://download.oracle.com/javase/tutorial/uiswing/components/slider.html

You can change stuff like FPS_MAX to COL_MAX = 255; Otherwise you can probably use the component pretty much as is
0
 
for_yanCommented:
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;

public class ColorPicker extends JFrame implements ChangeListener {

     JSlider js1;
     JSlider js2;
    JSlider js3;
    JPanel jp;


    public ColorPicker(){
         js1 = new JSlider (0,255);
             js2 = new JSlider (0,255);
            js3 = new JSlider (0,255);
            js1.setValue(0);
              js2.setValue(0);
              js3.setValue(0);

        js1.addChangeListener(this);
            js2.addChangeListener(this);
            js3.addChangeListener(this);

        jp= new JPanel();
        jp.setBackground(new Color(0,0,0));
        JPanel jp1 = new JPanel();
        jp1.setLayout(new GridLayout(1,3));
        jp1.add(js1);
           jp1.add(js2);
           jp1.add(js3);


        Container c = this.getContentPane();
        c.setLayout(new BorderLayout());
        c.add(jp);
        c.add(jp1, BorderLayout.NORTH);

        this.setSize(200,200);
        this.setVisible(true);






    }

    public void setColor(int i, int j, int k){
        jp.setBackground(new Color(i,j,k));

    }


    public void stateChanged(ChangeEvent ce){

        setColor(js1.getValue(), js2.getValue(), js3.getValue());


    }

    public static void main(String[] args) {

        new ColorPicker();
    }

}

Open in new window

0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now