Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)


Java AWT Dialog Example

About the AWT Dialog Example

In this example, we create AWT Frame which shows personal data. Here, fields Name and Age collect user input from the Frame itself. Address multi-line text field is read-only and ellipsis button next to it will launch a dialog to gather user input. The frame wants to display the address in a precise format and hence it invokes the dialog.

Once the dialog is displayed as modal, the code execution in the Frame window is blocked. This means, the user can not interact with any of the UI components in the Frame Window before closing the dialog. In the dialog, the user can fill the details required for the address field and click OK. Or they can also click Cancel and that is not a usual workflow.

the address information from the dialog and displays that in address multi-line field. Note, the frame gets the address in a formatted way from the dialog. Since, address field is disabled, the user can not edit its content manually. They can feed the address only via the dialog and there by the frame gets the formatted address.

Continue Reading →

AWT CheckboxMenuItem Example

AWT CheckboxMenuItem Example

In this example, we will learn how to use AWT CheckboxMenuItem and Menu Separator.

Here, we use our previous example on AWT Menu and change it to create CheckboxMenuItem. We create three checkbox menu items for Circle, Pentagon and Rectangle. In the above picture, we can also see a sunken line running between normal menu items and checked menu items. This line is called a Menu Separator. We create that here as well in this example.

Continue Reading →

AWT MenuItem and Menu – Example

Menubar Menu and Menuitem Relation

In the above picture, we can see a Frame Window is housing the Menubar. The same way a dialog also can show a Menubar. A Menubar can hold one or more menus. Here, the picture shows three menus named File, Edit, and Insert. Our Menubar can show only the Menu name in it. But when the user clicks it, it opens the pop-up Menu which contains one or more Menu Items. When the user clicks a menu item, the MenuItem will produce the ActionEvent which can be handled using the ActionListener.

Continue Reading →