File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 19541
    
  16

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: 19541
    
  16

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.
 
 
subject: SwingUtilities.invokeLater and invokeAndWait....
 
Similar Threads
Is paint/paintComponent method called by another thread?
SwingWorker and Modal JDialogs
Launching a modal Dialog at app startup through invokeLater() or not?
Updating GUI properties
difference between involeLater() and invokeAndWait()