wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes change the texts to a different one in a JButton each time it is pressed. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "change the texts to a different one in a JButton each time it is pressed." Watch "change the texts to a different one in a JButton each time it is pressed." New topic
Author

change the texts to a different one in a JButton each time it is pressed.

abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

hello friends i am new to gui programming.. i was testing the following simple code

BUT, i want the button text to change back to its old text the second time i click it .

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
button.setText(button.getText().equals("click me")? "button clicked":"click me");
abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

thank you
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10486
    
    9

Welcome to the Ranch.
In future, while posting code, please UseCodeTags. I have added them for you this time. As you can see the tags make the code much more easier to read and understand


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: change the texts to a different one in a JButton each time it is pressed.