wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Can't get an ActionListener to change a JLabel text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can Watch "Can New topic
Author

Can't get an ActionListener to change a JLabel text

Patrick de Kruijf
Ranch Hand

Joined: Mar 02, 2010
Posts: 63
Hello there,

I have to make a GUI with four buttons (north, south, east, west) that changes the text of a JLabel in the middle of a JPanel. When I compile and press a button, nothing happens.

I tried a lot of changes in the code, I started with String variable as an argument for the JLabel JLabel(labelText) and found out later on that there is a setText() method that does this. All nice things I've learned, but the button still doesn't work. Every time I fire it up, the button layout stays the same, and clicking the buttons do not change the text. I tried declaring the inner classes public, but that doesn't do the trick, I thought this wasn't necessary anyway.

What am I doing wrong? Hope you can help me, thanks in advance!



------------------8<------------------
please cut here
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You are only invoking center.setText() add the WestListener.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Moving to another forum where we usually discuss such questions
Patrick de Kruijf
Ranch Hand

Joined: Mar 02, 2010
Posts: 63
Thank you very much for your reply, and I appologize because I didn't show my appreciation earlier this week.

I had changed my code so many times that I was blind for this rather obvious mistake.

Thanks again, I am happy that the problem wasn't that big!

Hope to learn from you later,

Patrick
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Can't get an ActionListener to change a JLabel text