Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
abrar alvi
Ranch Hand
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya...reading it.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic