Dialogs are a type of Window that pop up over a parent Frame, usually to ask the user to confirm something or display an About box. Dialogs can be modal or non-modal. Modal dialogs monopolise the user’s attention, preventing him from clicking anywhere but in the dialog box. Early versions of Dialog were quite buggy.
JDialog is the Swing equivalent of Dialog.
Dialog constructors want a Frame as parent. Unfortunately, Applets are effectively Panels, not Frames. To embed a Dialog in an Applet, you must chase the Component. getParent chain until you find an instanceof Frame. Alternatively, you can pop up a new Frame for the Dialog to live in.
Modal Dialogs are most peculiar. They don’t immediately return to the caller when you call setVisible( true) followed by a return. They only return after the Dialog has disposed. Check out ColorChooser in FontShowerAwt for how you pass data gleaned from the user back to the code that invoked the Dialog.
In a nutshell, you first construct the modal Dialog, but don’t call setVisible( true ). Then you call a Dialog. query method that calls setVisible( true ) then returns the desired variables. Setvisible( true ) magically puts the query method on ice while the user interacts and finally hits OK or Cancel which triggers an ActionListener to call dispose. At that point the query method magically resumes executing, and can pick out whatever data it wants that the GUI (Graphic User Interface) interactions put into the Dialog fields. It can then bundle them into an Object or array to return to the caller.
If Dialogs fail to paint anything, it could be because you forgot to do a setSize, validate(), or setVisible( true ). Dialog.setBackground does not work.
This page is posted
Optional Replicator mirror
Your face IP:[220.127.116.11]
You are visitor number|