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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karimkhan
    New Member
    • Jan 2011
    • 54

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

    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:

    Code:
    PrimeThread p = new PrimeThread();
                p.start();
                jTextField1.setVisible(false);
                jTextField2.setVisible(false);
                p.sleep(1000);
                jTextField1.setVisible(true);
                p.sleep(2000);
                jTextField2.setVisible(true);
    but this does not work. All of them appearing at same moment!
    Last edited by Rabbit; Jan 14 '13, 05:27 PM. Reason: Please use code tags when posting code.
  • Anas Mosaad
    New Member
    • Jan 2013
    • 185

    #2
    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.

    Comment

    Working...