![]() |
Creating a GUI the Visual Way
This Magercise walks you through the creation of a simple Applet containing a Button and a Label. Pressing the Button sets the text of the label to "Self-destruct Initiated". Work LocationPerform all work for this magercise in VisualAge project MageLang Magercises, package magercises.creatinggui. If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name. Tasks
Perform the following tasks:
![]()
Create an applet using the visual editor by clicking on the applet
icon (an icon with the letter "A"): ![]() Type in "SimpleGUI" for the name of the applet. Notice that the dialog box lists SimpleGUI as the project automatically for you. Click the finish button. Make sure that the radio button "Design the applet visually" is selected. A dialog box will appear telling you that the default package for SimpleGUI does not exist. Answer that it should continue (that is, it should create the default package). VisualAge brings up the visual composition editor in response to your request for a new applet.
Add a Button to the applet. Using the visual composition editor,
click on the first icon (which looks like a button) of the
second column of the component list (on the left edge of the editor): ![]()
Add a label to the applet. Switch to the data entry components by clicking
on the second icon of the first column of the component category list on the
left edge of the composition editor window: ![]() ![]() Make a Button press set the text of the label to "Self-destruct initiated". Connect the actionPerformed event of the Button to the Label by right-clicking on the Button to get the popup menu. Select item "Connect" and then submenu item "actionPerformed". A dotted line will connect the Button to the cursor. Move the cursor over the Label and select it. Another popup menu will appear that asks you to indicate which property to change. Select the "text" item. Your composition editor should look something like:
![]() So far, you have specified that the Button will set the text property of the Label, but you have not specified what the text should be. Right-click on the connecting line between the Button and the Label to bring up the connection popup menu. Select "properties" from the menu (here "properties" refers to the properties of the connection not of the components). A properties dialog box appears. Click on the "Set parameters..." button. A new dialog box appears with the word "value" in the left column and a blank entry in the right column. Click in the right column, which opens a text field. Type "Self-destruct initiated" into the text field and click OK. Click OK in the properties dialog box. Test the applet. Under the "Tools" menu, select item "Test". VisualAge will bring up a dialog box asking for parameters and so on. Simply click the "Run" button as the defaults are fine. After a few moments, an applet viewer window appears with your Button and Label. Click on the "Self destruct" button and the label should change to "Self-destruct initiated".
|
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |