wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes SwingUtilities.invokeLater and invokeAndWait.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SwingUtilities.invokeLater and invokeAndWait...." Watch "SwingUtilities.invokeLater and invokeAndWait...." New topic
Author

SwingUtilities.invokeLater and invokeAndWait....

Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 88
Hi All,

Recently I came across a interesting question.

Why was SwingUtilitie.invokeLater() and invokeAndWait() method is designed in such a way that they accept RUNNABLE instances.
They could have created some new interfaces for this...

Any info on this would be really helpful.


Karthick D V
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Why would you need a new interface when an existing one is just fine? What would you need besides executing some code? Would you need parameters, and if so which ones?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 88
Hi,

I dont need to create any new interfaces.
Just wanted to understand why do these two methods take in Runnables.

Not sure if this is right or not.
Is it because internally all events in EventQueue are separate tasks and It will be easy for EventQueue to pick up each and every runnable and call run() on them?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Exactly. Sun could have decided to create a new interface, but they saw that Runnable was already there and provided them with all they needed - a single "run" method. The only possible problem with Runnable.run() is that it cannot throw any checked exceptions. Sun fixed that in java.util.concurrent.Callable, which also returns a value, but for Swing applications neither is really necessary.
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 88
I just came to know about Callable after your reply.

Thanks a lot.
 
Don't get me started about those stupid light bulbs.
 
subject: SwingUtilities.invokeLater and invokeAndWait....
 
Similar Threads
Launching a modal Dialog at app startup through invokeLater() or not?
difference between involeLater() and invokeAndWait()
SwingWorker and Modal JDialogs
Is paint/paintComponent method called by another thread?
Updating GUI properties