A well laid out user interface is an effective means of making applications user-friendly. It is typically used by organizations for accepting orders from customers, getting customer’s feedback on a product, for conducting a market survey on the latest trends in economy.
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:
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 ();
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.