Sample: Using the Visual Editor in your iSeries Java projects

Add iSeries libraries to your Java projects, add a Java Visual Class, and edit using the Visual Editor.

Time required

Allow 30 minutes to run the example with the supplied data and to review the output. The result displays the contents of an iSeries data file.

  1. Create a Java project called MyJavaProject.
  2. Add the libraries to your Java project:
    1. In the Package Explorer, right-click on MyJavaProject and select Properties.
    2. In the left pane, select Java Build Path.
    3. Click the Libraries tab, and select Add Library.
    4. Select iSeries Utilities and Toolbox and click Next and then Finish.
    5. In the Properties dialog box, click OK. The iSeries utilities and toolbox library is added to your project. It contains the four JAR files:
      • jt400.jar
      • jt400Servlet.jar
      • iseriesut.jar
      • iseriescomm.jar
  3. Now add a new Java visual class to the project.
    1. In the Package Explorer, right-click on MyJavaProject and select New > Visual Class.
    2. In the Package field, enter mypackage.
    3. In the Name field, enter JFormattedTableExample.
    4. In the Style list, expand Swing and select Frame.
    5. Under "Which method stubs would you like to create?" select public static void main(String[]args).
    6. Click Finish.
    screen capture of New Java Visual Class dialog

    The class automatically opens in the Visual Editor. In the Palette view you should see the iSeries Utilities and iSeries Toolbox for Java categories.

  4. In the Source view, change the code in the main method to display the frame. You can use code assist (Ctrl+space) when you are entering code; this automatically adds any required package import statements to the class. Enter the following code for the main method:
    	public static void main(String[] args)
    
    	{
    		JFormattedTableExample f = new JFormattedTableExample();
    		f.addWindowListener(new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {
    				System.exit(0);
    			};
    		});
    		f.setVisible(true);
    	}
  5. In the Design view, add AS400, RecordIOManager, and ListManager beans to the class:
    1. In the Palette, expand the iSeries Toolbox for Java category. Click AS400, then click on the editor to add the bean to the class.
    2. In the Palette, expand the iSeries Utilities category and repeat for RecordIOManager and ListManager.
  6. Add a JButton and a JScrollPane to the frame, and add a JFormattedTable to the JScrollPane:
    1. In the Palette, expand Swing components. Click JButton, then click on the North part of the frame to add the bean to the frame.
    2. Repeat for JScrollPane under Swing containers, adding the object to the Center part of the JFrame.
    3. From the iSeries Toolbox for Java category, select JFormattedTable. Click on the JScrollPane to add the bean.

    screen capture of Visual Editor

  7. Set the properties for the widgets:
    1. In the Design view, click the as400 icon to select it. In the Properties view, set the systemName, userID, and password fields for your iSeries system. Surround the generated code with try and catch blocks to handle exceptions (in the Source view, select the generated lines, right-click, and select Source > Surround with try/catch Block).
    2. Similarly for the recordIOManager icon, set the system property to as400 and also set the following properties:
      Property Value
      FileName PRODUCT
      Library ADTSLAB
      RecordFormatName PRODUC1

      Surround the generated code with try and catch blocks to handle exceptions.

    3. For the ListManager icon, under the property for DisplayContainer, select JFormattedTable from the drop-down list, and for the recordIOManager property, select RecordIOManager from the drop-down list.
    4. Finally add a label to the JButton by adding Press me to Update Table under the text property.
  8. Configure the Event Handler to the push button:
    1. Right-click the JButton and select Events > actionPerformed. Edit the generated code in the Java Editor by replacing the system.out.println() call with the following:
      getListManager().readAllRecords();
      Surround the generated code with try and catch blocks to handle exceptions.
  9. Save the application. The Java Beans view should look like this:

    screen capture of Java Beans view

In the Package Explorer, right-click on JFormattedTableExample.java and select Run > Java Application. Click the JButton to update the table.screen capture of application after running it