all access to Swingcomponents needs to be done from a single thread—the event-dispatch thread
how to know whether you are in event dispatch thread
method1:
EventQueue.isDispatchThread()
method2:
SwingUtilities.isEventDispatchThread()
how to give tasks to event diskpatch thread:
add runnable object to event queue
method1:
EventQueue.invokeLater(Runnable runnable)
don't care when the task finishes
method2:
EventQueue.invokeAndWait(Runnable runnable)
wait until task done
ex:
Runner runner = new Runnable(){
public void run(){
JFrame frame=new JFrame();
frame.setVisible(true);
}
};
EventQueue.
沒有留言:
張貼留言