This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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
 
GeeCON Prague 2014
 
subject: ChangeListener problem