Java Swing Tutorial - Java EventQueue .invokeAndWait (Runnable runnable)








Syntax

EventQueue.invokeAndWait(Runnable runnable) has the following syntax.

public static void invokeAndWait(Runnable runnable)    throws InterruptedException ,     InvocationTargetException

Example

In the following code shows how to use EventQueue.invokeAndWait(Runnable runnable) method.

//from w w w  .  j a v a2s  . co m
import java.awt.EventQueue;

import javax.swing.JFrame;

public class Main {
   public static void main(String[] args)
   {
      EventQueue.invokeLater(new Runnable()
         {
            public void run()
            {
               JFrame frame = new ImageProcessingFrame();
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               frame.setVisible(true);
            }
         });
   }
}

class ImageProcessingFrame extends JFrame
{
   public ImageProcessingFrame()
   {
      setTitle("ImageProcessingTest");
      setSize(200, 200);
   }

}