Using Abstract Windowing Toolkit (AWT) In Applications - How To Talk To Your Application
(Page 6 of 6 )
The Dialog Class: Dialogs are pop-up windows that are used to accept input from a user. There are two kinds of dialog boxes-
modal and modeless. Unlike a modeless dialog box, a modal dialog box does not allow a user to interact with other window while it is displayed. A frame or another dialog must own a dialog box. You cannot directly attached a dialog to an applet. You can attach a dialog to a frame.
When you create a dialog box, you can specify whether you want a modal or modeless dialog box. You cannot change the “modality” of the dialog box after creating it. We use Dialog class for creating dialog boxes. The dialog class offers overloaded constructors.
The following constructors create a dialog box that has a frame as its owner:
•Dialog (Frame owner_frame)
•Dialog (Frame owner_frame, String title).
•Dialog (Frame owner_frame, String title, Boolean modal).
The following constructors create a dialog box that has another dialog box as its owner:
•Dialog(Dialog owner_dialog)
•Dialog (Dialog owner_dialog, String title).
•Dialog (Dialog owner_dialog, String title, Boolean modal).
The single argument constructor creates a modeless dialog box without a title. The second argument that you could pass to a constructor is the title of the dialog box. To create a modal dialog box, you could use the third argument. An example is given below.
Dialog dialog = new Dialog (frame, “Demo Of Dialog”, true);
Getting To Know About PanelsThe Panel Class: Panels are used for organizing components. You can use the Layout Manager to decide how the components are to be arranged on the panel. Each panel can have a different layout. To create a panel, use the following command:
Panel panel = new Panel ();
Sub-Panels: You can also create what is called the “nested panels”, with one panel containing more than one sub-panels. You can nest panels, as many levels up as you like. Once you have created a component, the simplest way to add it to the container is to call the container’s add () method. For example:
Panel Mainpanel, Subpanel1, Subpanel2;
Mainpanel = new Panel ();
Subpanel1 = new Panel ();
Subpanel2 = new Panel ();
Mainpanel.add(Subpanel1);
Mainpanel.add(Subpanel2);
So we have covered some basics about Java AWT, discussed at length about the Component class. Enumerated on the first component-the container and its various types like windows, Frame, Panel and Dialog boxes. In the next part of the tutorial we will see how to simplify user interaction and make data entry easier, with the use of use controls. Controls are components like buttons and text box, check box, radio button etc. that can be added to containers like frame, panels and applets. We will also cover additional information about Java AWT package which provide an integrated set of classes to manage user interface components and then write a few codes to test our knowledge.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |