By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

How to add time event to show jframe component one after another?

P: 54
I want to create the visual expression of merge sort to explain it.

So what I want is first in textbox initial sequence of number. And the subsequently next state with some time delay sequentially.

Can any one tell me how to do.
I tried by creating Thread like:

Expand|Select|Wrap|Line Numbers
  1. PrimeThread p = new PrimeThread();
  2.             p.start();
  3.             jTextField1.setVisible(false);
  4.             jTextField2.setVisible(false);
  5.             p.sleep(1000);
  6.             jTextField1.setVisible(true);
  7.             p.sleep(2000);
  8.             jTextField2.setVisible(true);
but this does not work. All of them appearing at same moment!
Jan 14 '13 #1
Share this Question
Share on Google+
1 Reply


100+
P: 185
Sleep method is static. Which means when you call p.sleep, you are not sleeping p thread. You are sleeping the current thread. That's why you are unable to see the changes.

You will need to update the UI from the thread using SwingUtilities.invokeAndWait. May be this article will help you http://www.cab.u-szeged.hu/WWW/java/...g/threads.html.
Jan 14 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.