File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ChangeListener problem

 
Michael Cleary
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple JSLider which I want to use to place a value in a text field. I have used the exact same code before in another application with no problems. Now I'm getting a compile error. My code is below, followed by the compiler error:

//register JSlider event listener
jSlider1.addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent e)
{
jTextField1.setText(Integer.toString(jSlider1.getValue() ) );
}
}
);//end call to addChangeListener


<Compiler output>:
stbmonitor/nasmonitor/SetPollWindow.java [102:1] <identifier> expected
jSlider1.addChangeListener(
^
1 error


It must be something pretty simple, but I can't see it. I would appreciate a point in the right direction...

Thanks,
Mike
 
Michael Cleary
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change my code to the following, and now it works fine:

private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {
jTextField1.setText(Integer.toString(jSlider1.getValue() ) );
}

I don't understand why this works, and my anonymous inner class didn't. ??

Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic