2008年7月23日 星期三

event dispatch thread

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.

JTable

JTable's  mothod
getModel:
Returns the TableModel that provides the data displayed by this JTable.

modify table's behavior:
define a class that extends DefaultTableModel

DefaultTableModel's method
void addRow(Object[] rowData)

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.