0

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

napi15
  • 2,354
  • 2
  • 31
  • 55
  • instantiate `TColor` in the class where you want the result of function, then call the function using that instance. – jack jay Jan 13 '17 at 21:00
  • but I was wondering if it's a good thing to do – napi15 Jan 13 '17 at 21:00
  • In which class you are going to use that function? – jack jay Jan 13 '17 at 21:02
  • 1
    Also consider the approach examined [here](http://stackoverflow.com/q/2159803/230513). – trashgod Jan 13 '17 at 21:05
  • @jackjay in a third random class completely not connected to the Color chooser – napi15 Jan 13 '17 at 21:10
  • 2
    Use some kind of observer pattern which allows other objects to monitor changes the occur in TColor. You could also use a JDialog instead of JFrame, which allow you to display a modal dialog, allow the user to value and when closed you could use a getter to get the actual value – MadProgrammer Jan 13 '17 at 21:17
  • I will see what suits the best UI , thank you all for your advice – napi15 Jan 13 '17 at 21:20
  • 1) `ColorValueSliderControl` See also [`JColorChooser`](http://docs.oracle.com/javase/8/docs/api/javax/swing/JColorChooser.html) 2) Generally it's better to simply use instances of frames and panels, than to extend them – Andrew Thompson Jan 14 '17 at 03:03

1 Answers1

0

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

napi15
  • 2,354
  • 2
  • 31
  • 55