This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes change back text of button with help of Thread.sleep() 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 "change back text of button with help of Thread.sleep()" Watch "change back text of button with help of Thread.sleep()" New topic
Author

change back text of button with help of Thread.sleep()

abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

hi,
i want my button text to change automatically after 1 second to the default text which i have given.
i have used thread but its not working help me.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Don't use the == operator to compare the contents of two String objects, it compares whether the two objects are the same object. Clearly two different String objects can have the same contents. Use the equals() method to do that comparison.

And by the way, "Thread.sleep(200)" isn't going to sleep for 1 second. However even if it did, that code isn't going to do what you want. Read the Swing threading tutorial: Lesson: Concurrency in Swing to find out how to do it.
abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

thank you for the info. how do i automatically change the text of my button without clicking it
to its original text.

Here is the the full code without the DrawPanel class where i defined the paintComponent();
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You didn't read the tutorial, did you? 15 minutes is not nearly enough to go through it and understand it.
abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

ya...reading it.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: change back text of button with help of Thread.sleep()
 
Similar Threads
invoke method with reflection
Explicit Event Handling
Is there any problem with this code?
jButton revalidate, updateUI, repaint does not working
My first post (thank): report with subreport open