Top
Interstage Studio User's Guide
FUJITSU Software

7.2.3 Development Procedures

The actual procedures used to develop the applet are described below.

1) Creating the Project

2) Creating the Java Classes

3) Creating the I/O Page

4) Verifying the Applet Behavior

5) Distributing the Applet to the Operating Environment

1) Creating the Project

Select [File] > [New] > [Project] from the menu bar to display the [New Project] wizard.

Select [Java] > [Java Application Project] from the [New Project] wizard, then click [Next].

Check and enter the following setup items. After the following information is set, click [Finish].

Setup Items

Setup Content

Project name

AppletSample

Contents

Create new project in workspace

JRE

Use default JRE

Add project to working sets

Do not select

2) Creating the Java Classes

2-1) Creating the Data Class

Create a data class that stores the country name and total population information, and gets information. To create the data class, select the created project, then right-click to display the context menu. Select [New] > [Class] from the context menu. The [New Java Class] wizard is displayed.

Check and enter the following setup items. After the following information is set, click [Finish].

Setup Items

Setup Content

Source folder

AppletSample/src

Package

sample

Name

CountryData

The following source file is generated:

Source file

Description

CountryData.java

Data class

Implement the processing for storing the country names and total populations. Add the places shown in red below to the source.

Data Class Implementation (CountryData.java)

package sample;

public class CountryData {

    private String countryName;
    private int totalPopulation;

public CountryData(String name, int total) { setCountryName(name); setTotalPopulation(total); } public String getCountryName() { return countryName; } public void setCountryName(String countryName) { this.countryName = countryName; } public int getTotalPopulation() { return totalPopulation; } public void setTotalPopulation(int totalPopulation) { this.totalPopulation = totalPopulation; } }

Point

After the fields are added, and while the class is in the selected state, [Source] > [Generate Getters and Setters] can be selected from the menu to add getter/setter.

2-2) Creating the Logic Class

To create the logic class, select the created project, then right-click to display the context menu. Select [New] > [Class] from the context menu. The [New Java Class] wizard is displayed.

Check and enter the following setup items. After the following information is set, click [Finish].

Setup Items

Setup Content

Source folder

AppletSample/src

Package

sample

Name

PopulationRanking

The following source file is generated.

Source file

Description

PopulationRanking.java

Logic class

Implement the processing for entering the ranking and returning the country name and total population. Add the places shown in red below to the source.

Logic Class Implementation (PopulationRanking.java)

package sample;

public class PopulationRanking {
    
    private CountryData[] countries;
    
    public PopulationRanking(){
        
        countries = new CountryData[]{
            new CountryData("China",1330000000),
            new CountryData("India",1140000000),
            new CountryData("U.S.A.",300000000),
            new CountryData("Indonesia",230000000),
            new CountryData("Brazil",190000000),
            new CountryData("Pakistan",160000000),
            new CountryData("Bangladesh",150000000),
            new CountryData("Russia",140000000),
            new CountryData("Nigeria",140000000),
            new CountryData("Japan",130000000)
        };
        
    }
    
    public CountryData getCountryData(int rank) {
        --rank;
        if (rank < 0 || rank >= countries.length) {
            return null;
        }
        
        return countries[rank];
    }
    
}

3) Creating the I/O Page

3-1) Creating the Input Page Pattern

Create the applet to be used as the input window. To create the applet, select the project that was created, then select [New] > [Other] from the right-click context menu. From the wizard list, select [Java] > [GUI] > [Applet], then click [Next]. The [New Applet] wizard is displayed.

Check and enter the following setup items. After the following information is set, click [Next].

Setup Items

Setup Content

Source folder

AppletSample/src

Package

sample

The [New Applet] dialog box is displayed. Select [Applet] in the Java tab, then click [OK]. The applet wizard is displayed.

Check and enter the following setup items. After the following information is set, click [Next].

Setup Items

Setup Content

Package name

sample

Applet Name

PopulationRankingApplet

Base class

com.fujitsu.jbk.gui.JFApplet

Bounds

(80,170,400,400)

Font

Dialog,12

Foreground

Black

Background

White

To create the HTML, confirm and enter the following setup items. After the following information is set, click [Next].

Setup Items

Setup Content

Generate HTML

Select

Generate HTML for JBK plug-in

Select

Page title

World ranking for total population

Width of applet

400

Height of applet

400

Parameters are not used in this applet. Select "myItem0" in the parameter information, then click [Delete]. After deleting the parameter, click [Create].

3-2) Editing the Input Page

Use the Graphical Editor to edit the PopulationRankingApplet.java file that was created. Refer to "7.3.6 Editing a Java Form" for information on editing with the Graphical Editor.

Use the following procedure to paste Beans into the applet:

  1. From the list of objects displayed at the top of the properties window, select the applet.

  2. From the list of properties displayed at the bottom of the properties window, set the following values for the applet's properties. It is possible to change the setting according to property type by clicking or double-clicking the mouse on the property settings section.

    Property name

    Value

    layout

    <NONE>

  3. In the object palette of the Java Form Designer window, click [AWT].

  4. From the object palette, select the AWT label.

  5. Position it in the applet. Click on the location where the Bean is to be pasted to. Drag until it is big enough and then release the mouse button to paste the Bean.

  6. Similarly, paste two AWT labels (a total of three including the Bean pasted in the previous step), an AWT text field, and an AWT button.

  7. In the properties window, set the values shown below for the properties of the pasted Bean. Switch the [Standard]/[Original] tabs of the properties window, select the property, then change the value.

label1 [AWT Label]

Property name

Value

bounds

(24,24,256,24)

text

Enter a ranking from 1 to 10.

label2 [AWT Label]

Property name

Value

bounds

(24,80,48,24)

text

Rank:

textField1 [AWT TextField]

Property name

Value

bounds

(80,80,120,24)

text

label3 [AWT Label]

Property name

Value

bounds

(208,80,48,24)

text

Rank

button1 [AWT Button]

Property name

Value

bounds

(40,136,200,32)

label

OK

3-3) Entering the event process for the input window

In the Graphical Editor applet window, select Button1, then select [Event], [action], [actionPerformed] from the context menu. The event process "button1_action_actionPerformed" is added to the PopulationRankingApplet.java file. Add the places shown in red below to the source.

Event process "action_actionPerformed" of button1 (PopulationRankingApplet.java)

private void button1_action_actionPerformed$(java.awt.event.ActionEvent e) {
        if (!defaultEventProc$(e)) {
            // The process when the event is generated is described below.
            // Get input value
            int rank;
            try {
                rank = Integer.parseInt(textField1.getText());
            } catch (NumberFormatException ex) {
                rank = 0;
            }
           
            // Check input
            if (rank < 1 || rank > 10) {
                javax.swing.JOptionPane.showMessageDialog(
                      this,
                      "The input ranking is not within the specified range.",
                      "Error",
                      javax.swing.JOptionPane.ERROR_MESSAGE);
                return;
            }
            
            // Output of the result
            PopulationRanking pop = new PopulationRanking();
            CountryData country = pop.getCountryData(rank);
            StringBuilder message = new StringBuilder();
            message.append("The country with the ");
            message.append(rank);
            message.append("rank is\"");
            message.append(country.getCountryName());
            message.append("\".");
            message.append(System.getProperty("line.separator"));
            message.append("The population is");
            message.append(country.getTotalPopulation());
            message.append(".");
            javax.swing.JOptionPane.showMessageDialog(
                  this,
                  message,
                  "Result",
                  javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
}

4) Verifying the Applet Behavior

4-1) Setting Breakpoints

Set a breakpoint at the first line of the button1_action_actionPerformed$() method of the applet class. To set or delete a breakpoint, double-click the vertical ruler on the left-hand edge of the editor.

4-2) Executing the Applet

In the Package Explorer view, select the PopulationRankingApplet.java file then select [Debug As] > [Java Applet] from the context menu. The applet viewer starts, and the input screen opens.

Enter the population ranking in the [Rank] input field, then click [OK].

The applet runs and is interrupted at the breakpoints. Check the value of variable by Variables view. Select [Run] > [Step Over] from the menu and check the program state in the Variables view. For debug details, refer to "6.2.6.1 Debugging".

Point

If the [Java Applet] launch configuration has not been created yet, create it from [Run] > [Debug Configurations].

In addition to checking values, values can be changed from the Variables view.

Processing that has been interrupted by the debugger can be restarted by selecting [Run] > [Resume] from the menu. The result is displayed in the message box. Check that the country name and total population are displayed for the entered ranking.

5) Distributing the Applet to the Operating Environment

To distribute this applet to the operating environment, create HTML and JAR files.

5-1) Exporting the Applet

The JAR file is created with the Export wizard. To launch the Export wizard, select [File] > [Export]. From [Export] wizard, select [Java] > [JAR file].

The JAR Export wizard is displayed.

Check and enter the following setup items. After the following information is set, click [Finish].

Setup Items

Setup Content

Select the resources to export

Select only the following files in the AppletSample/src/sample folder:

  • CountryData.java

  • PopulationRanking.java

  • PopulationRankingApplet.java

Deselect any other files that are selected.

Export generated class files and resources

Select

JAR file

AppletSample\AppletSample.jar

Compress the contents of the JAR file

Select

5-2) Creating the HTML file

Create the HTML file and define the applet. This applet uses the template HTML file that was generated automatically when the project was created without any changes. Use an editor to open the PopulationRankingApplet-JBKPlugin.html that was generated automatically in the project and confirm that the following definitions are there:

Property name

Value

code

sample.PopulationRankingApplet.class

archive

AppletSample.jar

Refer to the "J Business Kit Online Manual" for information on how to create a new HTML file.

5-3) Distributing to the Operating Environment

Copy the following files (created above) to the same folder on the Web server of the operating environment:

Point

The HTML file and applet can be deployed to different locations by adding the codebase attribute to the applet definition that is defined in the HTML file. Refer to the "J Business Kit Online Manual" for details.