JSlider not showing

209 views Asked by At

I am attempting to write a slider that changes the value of a number in a box.

I am trying to set the slider's y location to 0 and set the size of the slider to 200px wide and 30px high.

I have already initialized the the slider instance, and the code for the numbered box is written correctly:

 NumberSlider ns = new NumberSlider(controller, "number", 0, 10, 5);
 ns.setSize(200, 100);
 ns.setLocation(400, 200);
 window.add(ns);

When placing this in my view class I get the box with a number 5 in it.

So now that I have the box, how can I use the JSlider so that it interacts with the numbered box?

Here is the full constructor:

 public NumberSlider(Controller c, String s, int min, int max,int ini_val){

 setLayout(null);
 slider_name = s;
 controller = c;
 Box box = new Box();
 box.setLocation(min, max);
 box.setSize(40, 30);
 String text = String.valueOf(ini_val);
 box.setText(text);
 add(box);

 JSlider jslider = new JSlider(JSlider.HORIZONTAL, min, max, ini_val);
0

There are 0 answers