Search code examples
javaswingcolor-picker

How to return values from Slider to control in swing Java


First I have implemented this class ColorValueSliderControl as described in this link ColorValueSliderControl

Now I have would like to return the values of this method of the Class TColor to another separated independant class

public class ColorValueSliderControl extends JFrame {
  public ColorValueSliderControl() {
    getContentPane().add(new TColor());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500, 500);
    setVisible(true);
  }
/*  Not needed 
   public static void main(String arg[]) {
    new ColorValueSliderControl();
  }*/
}
class TColor extends JPanel {
  ......
 //I want to return the result of this method to another class
  public Color  setBackgroundColor() {
   float [] colors = new float[3];
   color = new Color(redValue, greenValue, blueValue, alphaValue);
   return(color); 
    ......


  }

Thank you


Solution

  • I did solve my own problem , what I did is simply implement the color panel into my existing J Frame and it was much easier go get result of the chosen color by using getter and setter , and to update the color all I needed is use the existing Listener that exist in TColor class