Your First Applet

Team-Fly

Before you can create an applet with VisualAge for Java, you must install the software on your computer. To launch VisualAge, double-click the VisualAge for Java icon, or select Start, Programs, VisualAge for Java. The Welcome to VisualAge dialog box, shown in Figure 3.1, appears.

Clicking Close not only closes the dialog box, but also opens the Workbench window, which is where you usually create and change classes. The layout of the

click to expand

Figure 3.1: The Welcome to VisualAge dialog box

Workbench window depends on which tab is selected: Projects, Packages, Classes, Interfaces, or All. To switch to a different tab, click on it. The menu bar also changes as you switch from tab to tab.

To begin, select File, Quick Start from the Workbench menu bar. The Quick Start dialog box offers four options: Basic, Repository, Management, and Features. Select Basic, Create Applet, and then click OK. The SmartGuide dialog box, as seen in Figure 3.2, will help you create Java applets and applications.

Specify the project name as Java Applet, the package name as JavaApplet, and the applet name as Hello. Deselect the Browse applet when finished and the Compose the class visually check boxes, and click on the Finish button. At this point, SmartGuide creates the code needed for your new applet. To test your newly created applet, select the Hello applet, and then choose Selected, Run, In Applet Viewer from the Workbench menu bar, as seen in Figure 3.3.

The Applet Viewer runs the applet without having to use a Web browser. You can resize the window to see the complete message. To do so, you must change the properties of the applet by selecting the Hithere class in the Workbench and then

click to expand

Figure 3.2: The SmartGuide dialog box

click to expand

Figure 3.3: Run the Hello applet through Workbench

click to expand

Figure 3.4: An applet running in the Applet Viewer

choosing Selected, Properties. Figure 3.4 shows the result of the applet we created and ran with VisualAge for Java.

You can also modify the applet to display different output by selecting your class in the Workbench. To change the text 'Welcome to VisualAge' to 'I am having fun with VisualAge,' just type over the text and select Edit, Save from the menu bar. You can then test the result by compiling the code. To do this, choose Selected, Run, In Applet Viewer from the menu bar.


Team-Fly


Java & BAPI Technology for SAP
Java & BAPI Technology for SAP
ISBN: 761523057
EAN: N/A
Year: 1998
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net