Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes ChangeListener problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ChangeListener problem" Watch "ChangeListener problem" New topic
Author

ChangeListener problem

Michael Cleary
Ranch Hand

Joined: Jul 29, 2003
Posts: 93
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


Mike<br />SCJP 1.4<br />----------------------------<br />mdcleary@earthlink.net<br />----------------------------<br />There are 10 types of people<br />in the world. Those that <br />understand binary, and those<br />that don't.
Michael Cleary
Ranch Hand

Joined: Jul 29, 2003
Posts: 93
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ChangeListener problem
 
Similar Threads
Oversized JPanel
problem drawOval() cant be found.
Movie-like timeline with JSlider
simple slider question
Swing ChangeEvent occur twice