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.
2008年7月23日 星期三
2008年7月18日 星期五
JOptionPane
show message box
showConfirmDialog
Asks a confirming question, like yes/no/cancel.
showInputDialog
Prompt for some input.
showMessageDialog
Tell the user about something that has happened.
showOptionDialog
The Grand Unification of the above three.
訂閱:
文章 (Atom)