Host Access Beans for Java

Host Access Beans for Java

First Host Print Bean Applet

The HostPrintTerminal bean provides host print session support.  This bean requires the Host On-Demand Toolkit to compile and run. See Building Host Access Beans Applets for more information on the packages to import.

The following explains each statement or group of statements used in this sample program:

  1. Import the necessary packages as follows:
       import com.ibm.eNetwork.beans.HOD.*;        // Get the Host Access Beans
       import com.ibm.eNetwork.ECL.*;              // Get the ECL classes
       import java.applet.*;                       // Get the Applet class  
  2. Create a simple Java class called Simple3270Print that extends the Applet class, which gives us an applet that can be run in the appletviewer:
       public class Simple3270Print extends Applet {
  3. Create a HostPrintTerminal bean.
       HostPrintTerminal pTerminal = new HostPrintTerminal(); 
  4. Because we are extending the Applet class, we need to implement an init() method that will be called when an instance of pTerminal is created. The setSize statement sets the host print terminal's size:
       public void init()
             { setSize(450,450); 
  5. Set the host print session type for the bean:
          try { pTerminal.setSessionType(ECLHostPrintSession.SESSION_TYPE_3270_PRT_STR);
  6. Set the host name and whether the session automatically reconnects:
          pTerminal.setHost("myHost");
          pTerminal.setAutoReconnect(true); 

    In this statement, you need to replace "myHost" with the name of your telnet server.

  7. Add the bean to our applet and start communication::
          pTerminal.startCommunication(); } catch (Exception e){
          System.out.println("Exception =" + e);
        } add(pTerminal);
      }
    }
    

Here is the whole program, without the editorial comments:

/* A Simple3270Print Example */
import java.applet.*;
import com.ibm.eNetwork.beans.HOD.*;
import com.ibm.eNetwork.ECL.*;
public class Simple3270Print extends Applet
  {
    // Build a HostPrintTerminal bean
    HostPrintTerminal pTerminal = new HostPrintTerminal();
    public void init()
       { setSize(450,450);
          try
          { pTerminal.setSessionType(ECLHostPrintSession.SESSION_TYPE_3270_PRT_STR);
            // Instead of "myHost", enter the name of your telnet server
            pTerminal.setHost("myHost");
            pTerminal.setAutoReconnect(true);
            pTerminal.startCommunication();
          }
          catch (Exception e)
          {
            System.out.println("Exception =" + e);
          }
          add(pTerminal);
       }
   }

Finally, here's a simple HTML file to run the applet you created:

  <HTML>
  <HEAD>
  <TITLE>First Host Print Bean Applet</TITLE>
  </HEAD>
  <BODY>
  <APPLET CODE="Simple3270Print.class" WIDTH=600 HEIGHT=700>
  </APPLET>
  </BODY>
  </HTML>

To run Simple3270Print, save the sample program in a file called Simple3270Print.java and compile it. Ensure that your CLASSPATH environment variable is set correctly (see Building Host Access Beans Applets). You can run the Simple3270Print applet by executing the following command:

appletviewer Simple3270Print.html

[ Top of Page | Previous Page | Next Page | Table of Contents ]