Tutorial: Create an applet
This tutorial allows you to create an AWT Applet through the JBuild's integrated development environment. For more IDEs and its related components, please refer to "JBuilder Environment" in the Help menu.
This tutorial shows:
1. How to create an applet project
2, use the Applet wizard to create a APPLET
3, compile and run applet
4. Customize the user interface of the applet program
5, add AWT components, into choice, label, button, edit, and source code
6, configure the applet.
7, modify the HTML document
8. Run the configured applet from the command line
9, test applet
The whole tutorial is provided as an example to provide you with convenience. If you want to view the source code or run the program, open
/ Samples / Tutorials / FirstApplet
Firstapplet.jpx in the directory
. Due to jbuilder
The example is read-only for the user, and you can copy the entire example directory to other directory to get read /
Write permissions.
Before you start reading a tutorial, please read the profile, it discusses some important issues of applet.
In the tutorial section of JBuilder Quick Tips, some information about viewing and printing tutorials. In JBuilder Quick Tips, there is also a feature of JBuilder to make it easier for beginners. This tutorial's documentation and the documentation of other JBuilders, see "Documentation Conventions" in the Learning About JBuilder chapter
Overview:
Most importantly remember that when you design Applets, consider the restrictions on Java support (depending on the browser type you are using). In this tutorial, you will use the JDK1.3 AWT component to design your applet, which is usually supported by most browsers, such as Netscape Navigator and Microsoft Internet Explorer. However, if you want to design an applet that uses the Swing component, you have to consider your browser's ability to support Java. Typically, you can find the browser's support information for Java Applets from the tool, maybe you prefer to find from Netscape and IE Help menu. The most insurance design Applet method is to use the AWT components and JDK supported by your browser.
Note: More information about running Applets in JBUILD, review "Running Applets" in "Working WITH Applets" of Web Application Developer's Guide.
The GoodeVening Applet created in this tutorial contains a drop-down language selection list box. When you select a language, such as German, you will show "Good Event", "GUTEN ABEND" in the panel under the selection box. When you complete this tutorial, you will get the applet similar to the illustration below with JBuilder's Applet Viewer.
Http://blog.9cbs.net/yuxiaojie/gallery/image/8011.aspx
When you click Stop in Sun's Applet Viewer, you will get the following image: http://blog.9cbs.net/yuxiaojie/gallery/image/8012.aspx wants to get all the applet code, can go to the end of the tutorial . For further deep understanding of Applet and Deployment, please refer to the "Working With Applets" and "Deploying Java Program" I in Building Applications with JBuilder.
Step 1: Creating a project Before starting the tutorial, read the Applets, JDK versions, and Applet components that the browser supports supported in the outline will be read. Before starting to create your applet, you must have a project to store it. Project Wizard can help you create: 1. Select File | New Project to open Project Wizard. 2, do the following changes in the corresponding field in the Project Wizard step: A. Enter firstapplet in the Name field Note: When you enter the Project name, the Directory field is also automatically entered in the Directory field. By default, JBulider uses the name of this project to create the path name and class name of the project. More information about Home Directory, you can check "JBuilder Projects". B. B. Select JPX C in the Type list box. On the Item of Generate Project Notes File Took Hook When you select this option, Project Wizrd creates an HTML document for your Project and add it to Project. Accept the other default options in steps. Http://blog.9cbs.net/yuxiaojie/gallery/image/8013.aspx 1, click Next to enter steps. Http://blog.9cbs.net/yuxiaojie/gallery/Image/8014.aspx 1, accept all the default paths in step I, and note that compiled class files, Project Files, and Source Files are stored in which places are stored. For more information on how JBuilder stores files, please refer to "Managing Paths". Tip: If you like to create an applet with an early version of JDK, you can modify this step. Although the JBuilder personal version does not support JDK switching, you can edit the already existing JDK by configuring the JDKS dialog (Tools§configure JDKs). For JDK1.1.x, you need to download the JFC for JDK1.1.x-specificum. 2, click Next, enter step three. 3. Do the following changes in the corresponding fields of step three: A. Accept the default settings for Encoding and Automatic Source Packages. B. Enter good evening in the Title Field of Class Javadoc Fields. C. Enter your name, company name, and applet's Description in the appropriate option. Note: The contents of the Class Javadoc Fields will appear in the Project HTML document that has been comments as the header of the source code. http://blog.9cbs.net/yuxiaojie/gallery/image/8015.aspx 1, click the Finish button. The wizard has created a project file and documentation for you, and firstapplet.jpx and firstapplet.html can be seen in the Project panel. 9. Double-click the HTML file to see Project Notes in the Content Panel. Http://blog.9cbs.net/yuxiaojie/gallery/image/8016.aspx Step 2: Generating Source File Applet Wizard Creates a A.java file and an applet html file and put them in your creation Project. Some steps to generate these source files: 1. Select File | New and select the web tag. 2. Double-click the Applet icon to open the Applet wizard.
3. Accept the default package name: firstapplet, defen the default from Project Name (FirstAmet.jpx) to be used as Package Name. 4. Enter your GoodeVeningApplet in Class Name Field. Here are sensitive to casements. NOTE: The complete class name (package name) is firstapplet.goodeveningapplet.class 5, accept the default base class, java.applet.applet. CAUTION: If you use javax.swing.japplet to create your applet, the applet will not run on most browsers. When this paper is written, Swing is still not supported by the web browser. Refer to the detailed information in the overview. 6. Select Generate Standard Methods. Step One's page settings should be like this: http://blog.9cbs.net/yuxiaojie/gallery/image/8017.aspx 1, click next to step II. In this step, you can add the parameters required by applet. Wizard will be an HTML document for applet in tags
Add
tags
And insert the corresponding parameter code in the source code.
Applet
Parameters, equivalent to the application of the command line
Arguments
Allow you to customize you
applet
. This tutorial does not need to add any parameters.
?? Reference "Defining and use parageters"
Http://www.java.sun.com/docs/books/tutorial/applet/appletsonly/param.html
2, click Next to enter the Applet wizard, the third step
3, do the following changes in step three:
A. Accept the default option to generate an HTML page.
When you select this option, the HTML document calling Applet will be generated. This HTML document contains
Tags and other properties.
B. Enter good evening html page in Title Field.
This title will be displayed in the window of the web browser at the Applet.
C. Accept the default settings for other properties.
The steps of the Applet wizard are as shown below:
http://blog.9cbs.net/yuxiaojie/gallery/image/8017.aspx
HTML document
The tag contains the following properties:
Codebase
This property option indicates the relative path of the browser to find any .class files related to the Applet HTML document. The value of CodeBase is "." Indicates that all files related to HTML are in the same directory as it. The CodeBase property is required when the Class file and the HTML file are not in the same directory.
Code
This attribute is required, it will be automatically added by the JBuilder's Applet wizard, which is an init () method for complete class name (package name class name). You can view in the generated HTML. In this example, the full Qualified Class Name is firstapplet.goodeventingapplet.class.
Archive
This is an optional attribute that is not included in the Applet wizard, which is required when the applet is configured in JAR, ZIP, or CAB files. Archive Files must be in the directory indicated by CodeBase. Name
This is an optional attribute that indicates the name of the applet.
Width / height
This is a must-select attribute that determines the wide and high of the Applet display area, with pixel to measure.
HSpace / vSpace
These two optional attributes determine the fill distance of the APPLET's horizontal (left and right margins) and vertical (up and down margins).
Align
This optional property determines the alignment of the applet in the HTML page.
Focus: CodeBase, Code, Archive, and Name values must be sensitive to quotation marks and are sensitive. See "Working With Applets" in Web Application Developer's Guide "Working with Applets"
Tag Attributes "
theme.
1, click to complete the Applet wizard. Note that goodeveningapplet.java and goodeveningapplet.html have been created and added to the project. GoodeVeningapplet.java is already in the content panel
Note: If the Source Package Discovery and Compiction options of Project | Project Properties are allowed, an Automatic Source Package Node named at the firstApplet will appear in the project panel.
http://blog.9cbs.net/yuxiaojie/gallery/image/8018.aspx
Now look at the source code for two files. View GoodeVeningApplet.java noted some of the items * which contains the init () method. The HTML document containing the applet must call classes containing the init () method to make the applet run. * The first line of the code is the package name firstapplet. According to Java's custom class files are saved in the firstapplet directory. * Declare imported is AWT PACKAGES instead of swing: import java.awt. *; Import java.awt.event. *; Import java.applet. *;
?
2. Double-click GoodEVeningApplet.html in the Project Panel and select the source tag at the bottom of the content panel to view the source code. Please note the wizard insertion code value firstapplet.goodeventeningapplet.class. 3. Select File | Save All to save the source code and project files. Note: JBuilder Save the source file by default in /
/ jbproject / firstapplet / src / firstapplet /
?
Applet HTML file is saved in Classes Directory: /
/ jbproject / firstapplet / classes /
?
Class files, after compiling, saved in the output directory: /
/ jbproject / firstapplet / class / firstapplet /
?
JBuilder always saves files in accordance with the Package hierarchy. In this example, the code and Class files are saved in the code and output path, reflecting the structure of the FirstApplet package. These paths can be set through the project wizard, view in the Properties dialog box of the project. In this tutorial, you can accept the default settings for the JBuilder project wizard.
?
Step 3: Compile and run your applet
?
Now start compiling to run your applet. Compiling is a process running the Java compiler. The compiler is to translate the source code into a Java byte code, generate .class files. ?
Key: To know about the information about "Working With Applets" in Web Application Developer's Guide in JBuilder, you can check the "Running Applets" topic "Working With Applets" in Web Application Developer's Guide. 1. Select Run | Run Project, or click the Run button to compile and run the applet. Run menus and run buttons allow Applet to run the applet viewer of JBuilder, AppletTestbed. Tip: You can also right-click on the goodeveningapplet.html of the project panel and select RUN. This allows your applet to run in the Sun's AppletViewer command line tool.
?
Currently, the Applet window is empty because the applet has no user interface.
?
When you run your applet, any errors found when compiling in the message panel at the bottom of the AppBrowser. Modify the error and run the applet again.
?
Your applet will be displayed in JBuilder's AppletTestbed, as shown in the following figure: http://blog.9cbs.net/yuxiaojie/gallery/image/8019.aspx You can change the applet run through the applet tab of Runtime Properties Dialog Box. setting. You can select Project | Project Properties to open the Project Properties Dialog Box Select Run's label, select GoodeventingApplet in the RUN page. Click Edit. The settings in the Applet Tab control the behavior of run the menu and run icons in the toolbar. Select Main Class to make your applet run in JBuilder's Applettestbed. Select HTML to make your program run in Sun's AppletViewer. When you use Applet Wizard to create your applet, Main Class Option will be set to the default. Important: The Applets running in the HTML file will call the init () method in the class instead of running the .java file directly .java file. Anything that tries to run. Java files generate an error message (unless you have selected the Can Run Standalone option in step one in the Applet wizard): java.lang.nosuchmethoderror: main exception in thread "main" ?????? ????????????????? 2, select EXIT to close "Good evening" applet. 3. Right-click the GoodeVeningApplet tab of the message panel, select Remove "GoodeVeningApplet" to close the message in the run.
?
Step 4: Customize your APLLET user interface so far, Applet Wizard has generated an applet housing that you can use a variety of components to customize its interface, follow these steps: 1. • Select the top of the content panel to GoodeveningApplet.java file tag. 2. • Click the Design tab at the bottom of the content panel to switch to the design view. The UI Designer will appear in the content panel, and the upper part of its is the component panel, the right is the properties monitor of the component. You can use the component panel to add components to your UI, modify the properties through the property monitor, and add event triggers for your code. Now, the panel contains components that are made from UI, Menu, And Other. You can change the setting of the Applet through the applet tab of Runtime Properties Dialog Box. You can select Project | Project Properties to open the Project Properties Dialog Box Select Run's label, select GoodeventingApplet in the RUN page. Click Edit. The settings in the Applet Tab control the behavior of run the menu and run icons in the toolbar. Select Main Class to make your applet run in JBuilder's Applettestbed. Select HTML to make your program run in Sun's AppletViewer. When you use Applet Wizard to create your applet, Main Class Option will be set to the default. Important: The Applets running in the HTML file will call the init () method in the class instead of running the .java file directly .java file. Anything that tries to run. Java files generate an error message (unless you have selected the Can Run Standalone option in step one in the Applet wizard): java.lang.nosuchmethoderror: main exception in thread "main" ?????? ????????????????? 2, select EXIT to close "Good evening" applet. 3. Right-click the GoodeVeningApplet tab of the message panel, select Remove "GoodeVeningApplet" to close the message in the run. ?
Step 4: Customize your APLLET user interface so far, Applet Wizard has generated an applet housing that you can use a variety of components to customize its interface, follow these steps: 1. • Select the top of the content panel to GoodeveningApplet.java file tag. 2. • Click the Design tab at the bottom of the content panel to switch to the design view. The UI Designer will appear in the content panel, and the upper part of its is the component panel, the right is the properties monitor of the component. You can use the component panel to add components to your UI, modify the properties through the property monitor, and add event triggers for your code. Now, the panel contains components that are made from UI, Menu, And Other. Http://blog.9cbs.net/yuxiaojie/gallery/image/8020.aspx 3, change the layout in the property monitor from the default to borderLayout. ????????????? borderlayout arranges components in the area, named North, South, EAST, WEST, and CENTER. You can use this way to enable one or more edges of the container and with a component to fill the middle of the container. It can also allow you to fill the entire container with a component. ??????????? Note: XYLAYOUT in the drop-down box in the property monitor, JBuilder will automatically add a statement in the code com.borland .jbcl.layout. *. This important statement does not delete before you choose another simple layout method before you configure. The applet program you configure will not be able to run until you delete this sentence. Because Applet will look for JBCL Layout Classes to import import. You need to delete Zhejiang declarations in manual. JBuilder's UI Designer uses a default layout for each to the container, usually makes the AWT parent class container layout. In Java AWT, all panels use flowLayout as the default value. Click the extension icon of the component panel tree to see the layout manager of the panel. The layout manager is displayed below the parent class container in the form of an item. http://blog.9cbs.net/yuxiaojie/gallery/image/8021.aspx Select the AWT tab in the UI Designer Component panel You may need to scroll the component panel to find the AWT tag. Different from Swing components, AWT components are supported by most browsers. Note: UI Designer always opens Swing by default. You are very likely to choose the Swing component, so your AppleT is not able to run in the browser. Carefully select the component from the AWT page of the component panel. http://blog.9cbs.net/yuxiaojie/gallery/image/8022.aspx 5, add two panels to the panel. The top panel will be placed; a drop-down list box is used to select a language, and a Label used to illustrate this list box. The sub-panel of the bottom is expressed in different languages of "good evening". A. Press and hold Shift and click Components in the AWT panel, Java.awt.Panel. Press and hold SHIFT to pull multiple identical components at once without having to select a component in the component panel every time. Now you can add two panels. Tip: You can see the name of the component for a while on the component. B. Double-click this in the component tree, then add two panels, Panel1 and Panel2 will be added below the THIS of the component tree. C. Click the selection tool on the left side of the component panel to cancel the component selection. D. Check the Constraints property of the Panel in the Properties Monitor.
The top of the PANEL should be located in Northh, the PANEL at the bottom should be located in the center. Check the constraints attribute A. Select a Panel in the component tree or UI Designer. When a component in the Designer is selected, the boundary will appear on the corner angle. b. Confirm that in the attribute monitor, the top of the Panel set to North, the bottom of the Panel Set to Center. If not, you can click on the right of the constraints column, select the desired properties from the drop-down list. E. Rename the top of the panel as Upper: a. Select the top of the PANEL, double-click the column on the right of the attribute monitor Name property. b. Enter "Upper" and press confirmation. Tip: You can also right click on the components in the properties tree, select the rename in the menu. F. Name the bottom of the PAANEL. http://blog.9cbs.net/yuxiaojie/gallery/image/8023.aspx 6, change the background color of the Upper Panel to Orange: ??????????? A. Select Upper Panel. B. Click on the right side of the Background property. C. Click on the down arrow to open the color drop-down list, select Orange. 7. Change the Lower Panel's background color to Magenta 8 and change the Layout property of the Lower to CardLayout. CardLayout Panel will contain 5 PANELS, each of which corresponds to "good evening". CardLayout places the component (usually PANELS), just like a stack of cards. You can only see one at a time, you can choose which panel to be placed on top of the top to get the purpose of browsing. CardLayout usually accompanied by this controlled component, such as a check box? Or List. The status of the control component determines what components will be displayed. The user can make a decision by selecting selection on the UI. 1, hold down Shift to add 5 PANELS to Lower Panel. Each Panel will display "good evening" in a different language. Select "Select Tool" to cancel multiple selections. Tip: If you place the component in the wrong location, select it in the component tree, press the Delete key. Then add it again. 2, change the newly added PANELS 1 to 5 to BorderLayout. A) ???????? Press and hold the Shift or Ctrl. ?? b) ??????? Change the layout attribute to borderLayout. Now 5 Panel has a BorderLayout property. c) ?????? Select the other attributes in the group key tree or the UI Designer to cancel the selection of these Panels. 3, the background colors of 5 PANEL will be changed different. Tip: Click on the column on the right side of the property monitor and click the button on the right side of the dropboard to open the Background Color dialog. You can use the slider to create a color. 4, save the file and the entire project. 5, right click on GoodeveningApplet.html Select Run Use "GoodeVeningApplet.". When the applet is running in Sun's AppletViewer, you only see the top of Upper and Cardlayout's top Panel. After you add a drop-down box and add a list to select the event, the remaining language panels can be displayed. 6, exit Applet.
7. Right-click the GoodeveningApplet tab Close the message panel and select Remove "GoodeveningApplet". ?
Step 5: Add a AWT component to your applet Now you add a Label and Choice control to the top of Panel. 1. • Select the AWT tag of the component panel and select the Choice component. 2. • Place the component on the top orange panel, one of the following two methods can be used: a) ???????? Click the Upper Pannel in the component tree. b) ??????? Click Upper Panel in UI Designer. Now Choice1 is added to the UPPER tab of the component tree. 3. • Select the Label control and place it on the left side of the Choice control. Label is now added to the UPPER tab of the component tree. 4. • Select Label1 and perform along the following steps: a) ???????? Double-click the column on the right side of the Text property, so that the already existing text is high brightness. b) ??????? Enter "SELECT A LANGUAGE" and press Enter the confirmation, "SELECT A LANGUAGE" will appear in the Label control next to the Choice control. c) ??????? Click the Font property to modify the font, click the strip button on the right to open the Font dialog. d) ??????? Change bold to 20. e) ???????? Change the foreground color of the text, click the drop-down arrow, select Blue. Your design should be as follows:? Http://blog.9cbs.net/yuxiaojie/gallery/image/8024.aspx 5, hold down Shift Select the AWT Label component to add a Label control for Panel 1 ~ 5, each Both Label displays a language form of "Good evening", remember to click the selection tool on the left side of the component panel to cancel multiple selections. 6, a language that each Label is changed to "Good evening" is indicated. First, select the Label control under each sub-panel in the component tree, enter "good time" in the Text property, and give each Label assignment in the following correspondence: L ???????? Label2: good evening (English) L ???????? label3: guten abend (german) L ???????? Label4: Oodgay Vening EAY (PIG LATIN) L ????????? Label5: god Kväll (Swedish) L ???????? Label6: G'day, Mate (Australian) 7. Press and hold Ctrl to select Label2 to Label6, set them to bold, and font size is set to 24. Set the foreground color of the Label to black. Click on the component tree or the components in the UI Designer to cancel multiple selections. 8. Change the location of each Label by changing the properties of Constraints in the Property Monitor: L ???????? Label2: North L ???????? Label3: South L ?????? ?? Label4: East L ???????? Label5: West L ???????? Label6: Center Note: Note that in the BorderLayout panel, the center will populate the entire panel, while North South, EAST, and WEST are just part. 9. Change Panel 5's layout to flowLayout, the same as Upper Panel's layout. Note "G'day, Mate" Label move the middle of the top panel, when you want the component list, FlowLayout is a good layout. ?
Next, you have to add a button, and the FlowLayout layout will arrange it and Label in a column. FlowLayout arranges components from left to right in the same column. When a column is full, the rest of the components are moved to a new column. 10. Select the Button component of AWT and place it on the left of "G'Day, Mate" Label. Try to move Button to another place of Designer. FlowLayout always moves its moves and Label's location, your design should be similar to the following image: http://blog.9cbs.net/yuxiaojie/gallery/image/8025.aspx 10, choose file | save all To save the project. Select File | Save All to save the entire project.
?
Step 6: Edit your source code in this step, you will add a language list to Drop-Down, then add events to connect the language panel and the Choice component. 1. Add a language to the Drop-Down List in the init () method in the init () method: a) ???????? Click the Source tag in the content panel to switch to the code editor. b) ??????? The code of the init () method init () method in the left panel will be displayed high brightness in the editor. Tip: Click on the left structured panel and the name of the input method can look for a method. c) Move the cursor before the TRY / CATCH module and {, enter the Enter to create a new blank line. Tip: Select View | SHOW ALL to expand the editor and hide the project panel and structured panel. D. ??????? Add the following code to the init () method: // initialize the applet? Public void init () {??? choice1.additem ("English"); ??? choice1.addItem "German"); ??? choice1.additem ("pig latin"); ??? choice1.additem ("swedish"); ??? choice1.additem ("australian"); ??? Try {??? ?? jbinit (); ???} ??? catch (exception e) {????? E.PrintStackTrace (); ???}?} prompt: You can use CodeInsight to help you complete the code. Enter choice1. Then wait for a while or press Ctrl SpaceBar to display the pop-up window to display the calling method. Please ensure that Dot (.) Uses arrows after Choice1 to select AddItem (String) to press Enter. You can configure codeinsight http://blog.9cbs.net/yuxiaojie/gallery/image/8026.aspx if you have syntax errors in your code, structured An error folder will appear in the panel, open the folder, select the error message, and the error part in your source code is displayed in high brightness.
?
Next, you have to connect events and language to connect. When you choose a language in the Drop-Down List, "Good Event" in the CardLayout Panel will be displayed in different languages.
?
1, along the following steps to connect the Choice List event: a) ???????? Return to the UI Designer B) ??????? Select the choice1 C under the Upper Panel in the component tree. ????? Select the Events tab D) in the property monitor) ??????? Double-click the ItemStateChanged event JBuilder will generate the code of the method, and move the cursor to the source code insertion method. Void Choice1_ItemStateChanged (ItemEvent E) {????} e) ??? Add the following code to connect the language selection and language panel: void choice1_itemstatechanged (itemEvent E) {??? if ("English" .Equals (choice1 .getSelectedDitem ()) {????? cardlayout1.show (lower, "panel1"); ???} ??? Else if ("german" .Equals ())) {? ?? ?? Cardlayout1.show (Lower, "Panel2"); ???} ??? Else IF ("Pig Latin" .Equals (choffe1.getSelectedItem ())) {????? cardlayout1.show (Lower, " Panel3 "); ???} ??? Else if (" Swedish ".Equals (choice1.getSelectedItem ())) {????? cardlayout1.show (Lower," Panel4 "); ???} ?? Else if ("Australian" .Equals ()))) {????? cardlayout1.show (lower, "panel5"); ???}?} prompt: You can swim code template to generate code . Enter IF and press Ctrl J to get the pop-up of the code template. Use the arrow keys to make a selection. Select the IF-Else IF module, press Enter, this code is generated: if () {????????}? Else if {????}? 2 ,? Select File | Save all 3 , Right-click GoodEVeningApplet.html in the Project Panel, select "GoodeVeningApplet." To run the applet. "Good evening" applet runs in Sun's AppletViewer: http://blog.9cbs.net/yuxiaojie/gallery/image/8027.aspx If there is any error message, they all appear in the message panel at the bottom of the AppBrowser. Select an error message and press F1 to get help. Select the error message so that they show high brightness in the editor. Maybe sometimes, the error may appear before or after high brightness, correct the error, save the project, and re-run the applet. 1. Test the Drop-Down List. The language selection in the list will match the language in the language panel. 2, exiting the applet. Now add the Button's tag and Button event to Panel5's Button1. When you click on the button, Label6's "g'day, Mate" text color will become red.
1. Add the following steps to add Button's labels and Button events: a) ???????? Switch to UI Designer B) ??????? Select the Button1 on Panel 5 and then change the Label property from Button1 For the PUSH ME. Press to confirm. Note that the button will automatically adjust the size to adapt to the text. c) ??????? Select the Events tab of the property monitor to define what event will occur when the button is pressed. d) ??????? Double-click ActionPerformed Event: JBuilder will switch to the skeleton portion of the code added to the ActionPerformed event in the editor. Tip: Double-click the Button button in Designer can also achieve the same effect. Now enter the code, define the button event, so that "g'day, mat" is red. e) Enter the following code: void button1_Actionperformed (ActionEvent E) {? label6.setForeground (New Color (255, 0));} 2, and save the project. 3, run the applet and select "Australian" in the Drop-Down List. Click the "Push ME" button. "G'day, mat" will turn red. Your applet should be similar to the figure below: http://blog.9cbs.net/yuxiaojie/gallery/image/8028.aspx 1,? Exit Applet. ?
Step 7: Configuring your applet Configuring a java applet is a large package that a variety of Java Class files, image files, and other files needed, and copy them with the Applet HTML file to a server or client. Local so that they can be executed. You can transfer them separately, or you can transfer them to compress or uncompressed file files. JAR FILES, JAVA Archive Files is the most common form. JAR FILES has the advantages of small files and fast download speed. When you configure the applet, remember the following points: L ???????? Save before configuring and compile your project. l ???????? Open goodeveningapplet.html, click the Source tab, review the following steps: n ???????? The core to the Code property is not Fully Qualified Class Name, including package name. In this example, the value of the Code should be firstappplet.goodeventeningapplet.class.. n ???????? The check is specified in the correct relative path of the HTML file. In this example, the CodeBase value is "." Because JAR File containing the Class File will be in the same directory with the HTML file. l ???????? Keep the existing directory structure. In this example, GoodeventApplet.class reflects the package structure firstapplet.class in the firstApplet directory. If you want to configure JAR File, check the directory structure of the file to match the L ??????? to hold the existing directory structure. In this example, GoodeventApplet.class reflects the package structure firstapplet.class in the firstApplet directory. If you want to configure JAR File, check the directory structure of the file makes it. l ???????? Transfer all the needs of the Class file to the appropriate Internet Server. The relative paths of Class Files and HTML FILE must match the CodeBase property. l ???????? Put the HTML Files under the appropriate path of the Internet Server. ?
Note: If you are in order to obey the old version of the browser (JDK 1.02), please remember that Jar Files is not supported, you have to replace it with Zip archive file.
?
Use Archive Builde to configure your applet
?
JBuilder's Archive Builder checks all the necessary files that publish your applet and archive them as Jarfiles.
?
Configure your applet: 1, save your project. 2, select Project | make provject "firstapplet.jpx" to compile your project. 3, in /
/ JBProject /
Create an Applet directory for your applet under the path. This will be the directory of HTML File and? Jar File you place and tested. 4, select Wizards | Archive Builder to open Archive Builder http://blog.9cbs.net/yuxiaojie/gallery/image/8029.aspx 1, in step one's Archive Type's drop-down box Select Applet JAR Click Next Next step. NOTE: When you develop Applets for the old version of the browser that does not support JAR Files, select Applet Zip. 2, accept the default name of Applet Jar. 3, click on the point of the File field, browse to // jbproject / applets /
Under contents. 4, change the JAR file name of the File Name field to GoodeVening.ja then click to confirm. Step 2 should be as shown below: http://blog.9cbs.net/yuxiaojie/gallery/image/8030.aspx 1, click Next to go to the next step. 2, accept the default settings of step 3. Step 3 As shown in the following figure: http://blog.9cbs.net/yuxiaojie/gallery/image/8031.aspx 1, click Next NEXT proceeds to step 4. 2, NEXT proceeds to step 5 You don't need to add any libraries. 3, accept the default settings in step 5. Note that the Manifest Setting option is set to Create a manifest file. 4, point finish to exit Archive Builder. A node called Applet Jar appears in the project panel, you can select Properties to modify it by right-click. 5, right click on the Applet Jar Archive node and select Make to compile the project. Archive Builder will collect the firstapplet package you added in step 3 in Jar File. 6, click Applet Jar Archive Expand icon to view GoodeVening.jar Archive File. 7. Double-click Jar File in the project panel. Manifest File appears in the Content Panel, the contents of JAR Files appear in the Structure Pane. Select the Structure Pane file and view it in the Content Panel. Note: If you have to transfer multiple programs to the same location, you can re-categroup files instead of containing them in every JAR file.
?
Step 8: Modifying the HTML file so far from your applet is configured in the JAR file, you need to modify the Archive property in the HTML and contain the file name of JAR. You can also
Add messages to the tag to tell the user that it is not allowed
Java
In the browser, they will not see
applet
Unless they run
Java
Or upgrade their browser.
Modify the HTML file:
1. Open GoodEVeningApplet.html in JBuilder, add the Archive property as follows:
a) ???????? Select the Source tag to view the HTML source code.
b) ???????
Tag
Add the following
HTML
Code:
Archive? = "GoodeVening.jar"
Tag
It should be similar to this:
? CodeBase = "."
? code ???? = "firstapplet.goodeveningapplet.class"
Archive? = "GoodeVening.jar"? Name ???? = "TestApplet"
? width ??? = 400
? HEIGHT ?? = 300
? hspace ?? = 0
? vSpace ?? = 0
? align ??? = TOP
>
?
Tip: If your applet has multiple JAR files, you can arrange them, separated by a comma, such as: archive = "file1.jar, file2.jar"
Important: Some browsers do not support a list of JAR files and multiple archive files, but they are sure to support only one separate ZIP file in the Archive property.
Next, add a message, tell the user, do not allow Java's browser or their browser does not support Java, so they will not be able to see the applet.
2, in
tags
Enter the following message at the open and close junction:
You NEED A JAVA-Enabled Browser Running JDK 1.1.x or greater to view this applet
your
tags
Should be similar to:
? CodeBase = "."
? code ???? = "firstapplet.goodeveningapplet.class"
? Archive? = "GoodeVening.jar"
? Name ???? = "TestApplet"
? width ??? = 400
? HEIGHT ?? = 300
? hspace ?? = 0
? vSpace ?? = 0
? align ??? = TOP
>
?
You NEED A JAVA-Enabled Browser Running JDK 1.1.x or greater to view this applet.
Any browser that does not support Java will ignore
tags
And display
tags
The message between. Because of support
Jiava
Browser recognizes
Tags,
It should be seen here.
applet
Instead, what we just added.
Important: Before we save the HTML file, verify the following CodeBase and Code values again. If these two values are wrong, the applet will not be run. Remember, the value of CodeBase represents the relative location of the Applet code (Class or JAR) file and the HTML file. Value ".", Indicating that the Class file is in the same directory with the HTML file. The value of the code must be the project's Fully Qualified Class Name for the applet, which contains package name.
3, save and close the file.
4, the modified goodeveningapplet.html is copied from the item's CLASSES directory to the Applets directory. The Applet directory should contain two files goodeveningapplet.html and goodevenging.jar.
Note: Remember that JBuilder creates two html files: Project Notes HTML file, and firstapplet.html, place the root of the project and the applet html file contains
Tag, goodeveningapplet.html,
Placed in the project
SRC
Under contents. Don't copy
FirstApplet.html
Instead of
GoodeVeningapplet.html
Until
Applets directory, otherwise you
applet
Will not be run.
?
Step Nine: Run the configuration from the command line configuration applet
It is a good way to test the local test before placing the Web test. You can use Sun's AppletViewer to do this. It will tell you if the web browser already has everything you need to run Applet. If some files are missing or there have been some errors in the HTML file, the applet will not be run. You can modify the error before placing it on the web.
Run the applet from the command line:
1. Confirm that the copy of goodeveningapplet.html and goodeventing.jar is in the applets directory.
2, open the command line window.
3, follow the following methods to remove this session any ClassPath Variables:
L ???????? Windows NT, 2000, and XP: SET CLASSPATH
L ???????? Unix:
n ???????? IN CSH shell: unstenv classpath
n ???????? in sh shell: unset classpath
4, go to the applets / directory.
5, enter the following command to run AppletViewer:
/
/
/ bin / appletViewer goodeveningapplet.html
among them
On behalf of you running JBuilder, such as JBuilder6 /.
Important: If JBuilder is on another drive, you must contain a drive letter.
Note: For Windows, use backslashs (/).
If the "Good evening" applet can be loaded in AppletViewer, it indicates that the configuration is successful, and all CLASSES files can be found and included. If the applet cannot be run, view the error message, modify, recompile, configure, and test.
"Good evening" applet can be obtained from Samples / Tutorials / Firstapplet / in the JBuilder installation directory.
If you have an error, check the source code for the final applet of the tutorial when running the applet, and view the following common error topics:
l ???????? "Solving Common Applet Problems" At http://www.java.sun.com/docs/books/tutorial/applet/problems/index.html "
L ???????? Common Mistakes in the
Tag "and" Additional Tips for Making Applets Work "IN" Working with applets "in the Web Application Developer's Guide
?
?
?
The final step of developing Applet is to test on the Web, run. It can tell you if there is already all the needs of the need. Although this tutorial did not explain how to test, "Testing Your Deployed Applet On The Web" gives an overview.
?
Congratulations! You have created your first applet with JBuilder. Now you are familiar with the development environment of JBuilder, you will find that it has many simple features that make your programming work.
?
Other Applet tutorials can be viewed:
L ???????? "The Java Tutorial" at http://java.sun.com/docs/books/tutorial/index.htmll ???????? Charlie Calvert's Part II: Applets At HTTP : //homepages.borland.com/ccalvert/javacourse/index.htm
L ???????? Rich Wilkman's Curmudgeon Web Site At http://www.formlessvoid.com/jc/index
l ???????? john
Moore
's "applet design and deployment" at http://www.microps.com/mps/p_appletdesign.htm
?
Step Nine: Test your applet on the Web
?
The final step of developing Applet is to run your applet on the web. It can tell you if it really has all the files required to run. Testing your applet on multiple different browsers is important, it can confirm that all files are included in the file file. This tutorial does not involve specific test details, the following is some test guidelines:
Complete the following steps, then run your applet on different browsers to test your applet:
1. Send the HTML and JAR files of the applet to the Internet Server or copy to Windows NT Server.
a) Use FTP (File Transfer Protocol) to transfer files to the server. Make sure to transfer in binary
b)? Make sure the HTML and JAR file is in line with the CodeBase property in the HTML file, and the Code property is indeed Fully Qualified Class Name.
2, test the applet in multiple different browsers, if the applet is loaded, check whether the browser allows Java. At the same time, check the error message of the Java console of the following browser.
Open the Java console:
l ???????? Select to select Communicator | Tools | Java Console in Netscape.
The validity and accessibility of Java Console differ from the browser version.
3, correct the error, reconfigure your applet, and then test your applet in the browser.
?
?
Tomsawyer translation
2004
year
8
month
5
day
?
?
?
?
?