Java Swing Question and Answers

30. What is the main difference between Dialog and Frame?
  • In AWT, the top level window, which is itself not contained in another window, is called a FRAME.
  • On the other hand, a window that appears over existing window (mostly Frame) and forces the user to respond is called a DIALOG.
Frame f = new Frame(); // creates an object of type Frame.
A FRAME can exists on its own , where as a DIALOG cannot exist on its own. In other words, FRAME is a primary window, where as the DIALOG box is secondary window. The dialog boxes are of two types:
  • modal – This dialog won't let the user interact with the remaining containers/windows until he deals with it.
  • modeless - The user can interact with other windows as well as the dialog box, e.g. the toolbox.
    There is no default constructor for a DIALOG. The following statement constructs a dialog box:
    public Dialog( Frame parent, String title, boolean modal) Here:
  • parent – The container to which the dialog belongs.
  • title – Title of the dialog
  • modal – True for modal type, false for modeless type.
Your Name Your Email-ID
Your Answer
31. Explain Thread Rule in Swing?
  Once a swing component has been realized, i.e. the component has been painted on screen or it is ready to painted, all the code that might affect or depend on the state of that component should be executed in the event dispatching thread. This is called thread rule in swing.
Your Name Your Email-ID
Your Answer
123456789 Page 9 of 9