Why JSlider event listener no response?

Thanks,

hi, the JSlider does exist, but when it slides, data is unchanged.

Please help.

import java.io.*;

import java.awt.*;

import javax.swing.*;

import java.util.Hashtable;

import java.awt.event.*;

import javax.swing.event.*;

// import AppletAndApplicationExample.AppQuitter;

publicclass Comboxextends JApplet

{

...

private LayoutManager Layout;

private Container Panel;

private Drawing drawing;

..private String energyId[];

...

privateint numberofCells;

privateint numberofsets;

privateint id;//PlotEnergyId

privatedouble lineWidth;

privateint min = 1, max = 16, inc = 5;

double scale = 1.0;

private String currentPattern;

private JSlider dJSlider;

publicvoid init(){

Layout =new BorderLayout ();

getDrawingData();

dJSlider =new JSlider(min, max, 6);

drawing =new Drawing();

Panel = getContentPane();

Panel.setLayout (Layout);

Panel.add (drawing,"Center");

JPanel sliderPanel =new JPanel();

sliderPanel.setLayout(new BoxLayout(sliderPanel,

BoxLayout.PAGE_AXIS));

dJSlider.setAlignmentX(Component.LEFT_ALIGNMENT);

sliderPanel.add(dJSlider);

dJSlider.setMajorTickSpacing(5);

dJSlider.setMinorTickSpacing(1);

dJSlider.setSnapToTicks(true);

dJSlider.setLabelTable(getLabelTable(min, max, inc));

dJSlider.setPaintTicks(true);

dJSlider.setPaintLabels(true);

dJSlider.addChangeListener(

new ChangeListener()// anonymous inner class

// handle change in slider value

{

publicvoid stateChanged(ChangeEvent e)

{

int value = ((JSlider)e.getSource()).getValue();

scale = (value+4)/10.0;

}

}

);

Panel.add(sliderPanel,BorderLayout.NORTH);// ADD Slider

scaleData();// use JSlider to obtain new data

System.out.println(scale);// [b]found unchaged data,scale =1,why?[/b]

}

private Hashtable getLabelTable(int min,int max,int inc){

Hashtable<Integer, JLabel> table =new Hashtable<Integer, JLabel>();

for(int j = min; j <= max; j+=inc){

String s = String.format("%.1f", (j+4)/10.0);

table.put(Integer.valueOf(j),new JLabel(s));

}

return table;

}

publicvoid getDrawingData()

{...

}

publicvoid scaleData()

{

for(int i = 0; i < numberofCells; i++)

{

for(int j = 0; j<cellsPointsNumber[i]; j++)

{

xCells[i][j] = (xCells[i][j])*scale+TRANSITION;

yCells[i][j] = (yCells[i][j])*scale+TRANSITION;

}

}

}

publicstaticvoid main(String[] args){

/* Set up the frame that holds the applet. */

JFrame appletFrame =new JFrame("My Applet");

Applet theApplet =new Combox();

appletFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

appletFrame.setSize(800,800);

appletFrame.add(theApplet,"Center");// applet fills

// frame

/* Now start invoking applet methods. */

theApplet.init();

// applet

appletFrame.show();// bring frame and initialized

// applet on screen

theApplet.start();

theApplet.stop();

theApplet.destroy();

}

}// end class

>

[6578 byte] By [ardmorea] at [2007-11-27 10:01:23]
# 1
> System.out.println(scale);// found unchaged data,scale =1,why?Because you're only executing this line of code once. You're not doing it every time the event listener is fired (inside the stateChanged method).
warnerjaa at 2007-7-13 0:34:33 > top of Java-index,Java Essentials,New To Java...
# 2
your slider appears to update scale, but what do you do with the scale data once it's updated? I can't see that you're doing much with it. Do you need to call any methods from within your slider changelistener? scaledata() perhaps?
petes1234a at 2007-7-13 0:34:33 > top of Java-index,Java Essentials,New To Java...
# 3
> System.out.println(scale);// [b]found unchaged data,scale =1,why?[/b]scale is 1 because you set it to 1.0 initially and you never changed it. Notice that this line is executed just once in the init() method. It is not part of the change listener.
pbrockway2a at 2007-7-13 0:34:33 > top of Java-index,Java Essentials,New To Java...
# 4
anyone else want to join in here?
petes1234a at 2007-7-13 0:34:33 > top of Java-index,Java Essentials,New To Java...
# 5
petes1234, I am going to call scaledata().
ardmorea at 2007-7-13 0:34:33 > top of Java-index,Java Essentials,New To Java...