Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
change the texts to a different one in a JButton each time it is pressed.
abrar alvi
Ranch Hand
Posts: 66
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello friends i am new to gui programming.. i was
testing
the following simple code
public class SimpleGui implements ActionListener { JButton button; public static void main(String[] args) { SimpleGui gui=new SimpleGui(); gui.go(); } public void go() { JFrame frame=new JFrame(); button=new JButton("click me"); button.addActionListener(this); frame.add(button); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,300); frame.setVisible(true); } @Override public void actionPerformed(ActionEvent event){ button.setText("button clicked"); } }
BUT, i want the button text to change back to its old text the second time i click it .
Michael Dunn
Ranch Hand
Posts: 4632
posted 12 years ago
2
Number of slices to send:
Optional 'thank-you' note:
Send
button.setText(button.getText().equals("click me")? "button clicked":"click me");
abrar alvi
Ranch Hand
Posts: 66
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thank you
Maneesh Godbole
Bartender
Posts: 11497
19
I like...
posted 12 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
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!
]
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Swing simple
Error !! in Swing
programming style
need help with my code
function scope?
More...