I watched a tutorial yesterday trying to learn more about java programming....and have read several books in the last couple of years and I can't figure this one out.
The tutorial code was:
public class Slider extends JSlider{
public Slider{
JSlider redSlider = new JSlider(SwingConstants.HORIZONTAL,0,255,0);
redSlider.addChangeListener(new listener());
//and the rest of the code
}
public class listener implements ChangeListener{
public void stateChanged(ChangeEvent e){
int r = redSlider.getValue(); //cannot resolve redSlider
}
}
}
My question is the program compiles and runs on the tutorial, however when I write the code in JAVA7 and Eclipse Indigo I get unable to resolve redSlider in the listener
stateChanged method. I have worn Google out today, read my books and watched other tutorials, I can't figure out what I'm doing wrong. I thought that this would be an inner class and that inner class had access to the enclosing class variables. I really appreciate any help, of course I'm gonna continue looking myself.
Thanks,
Darryl