Jump to content

Struggle with Runnable(AGAIN)

- - - - -

  • Please log in to reply
3 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Hello,

I'm having trouble with Runnable :crying: one more time. I have this piece of code in my class:


if(success){

	SwingUtilities.invokeLater(new Runnable() {

	     public void run() {

	           Congratulation congratulation = new Congratulation();

	            congratulation.setVisible(true);

	            /*try {

			Thread.sleep(3000);

			congratulation.dispose();

		       } catch (InterruptedException e) {}*/

        }

});

As it is (Thread.sleep() commented) working fine. But when trying to have 3 sec and after this dispose() my image on congratulation Frame not displayed, :confused: but I can see the Frame that created.

Please help

Thank you,
toto7

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
Im not that good with Threads in Java but i found a thread that might help you form the Java forums:
dispose() does not work here

Hope that would help you.
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/

#3
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
I'd use a timer instead:
How to Use Swing Timers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)

Working with concurrency isn't an easy task by the way.

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
You make the Swing thread sleep, so everything swing related won't do anything anymore.
But, if you see your frame without an image.. are you sure the code of the frame isn't wrong, rather than this thread code?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users