Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Struggle with Runnable(AGAIN)


  • Please log in to reply
3 replies to this topic

#1 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 04 December 2011 - 05:30 AM

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
  • 0

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

-Michael Sinz

#2 Rakso

Rakso

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 335 posts
  • Programming Language:PHP, JavaScript
  • Learning:C++, PHP, Python, JavaScript

Posted 04 December 2011 - 07:04 AM

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.
  • 0

I am a freelance web developer & web designer. I loves to make websites and would be happy to work with you.

Check out my portfolio: http://oskarmendel.me/


#3 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts
  • Programming Language:C, Java, PHP, JavaScript
  • Learning:PHP

Posted 04 December 2011 - 08:51 AM

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.
  • 0

#4 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 05 December 2011 - 01:40 AM

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?
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download