Host Access Beans for Java

Host Access Beans for Java

Terminal Sample Program

The Terminal bean provides a traditional emulator GUI and is sometimes referred to as a "green screen" emulator. The Terminal 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.ECLSession;     // Get the ECLSession constants
       import com.ibm.eNetwork.HOD.common.*;       // Get the Environment class
       import java.applet.*;                       // Get the Applet class
       import java.awt.*;                          // Get Frame and Color classes
       import java.util.*;                         // Get the Properties class 
  2. Create a simple Java class called TermTest. Extend the Applet class which gives us an applet that we can run in the appletviewer:
       public class TermTest extends Applet { 
  3. Create two different Host Access Beans, a Terminal bean and a KeyPad bean.
         Terminal myTerm;
        KeyPad myPad; 
  4. Because we are extending the Applet class, we need to implement an init() method that will be called when an instance of TermTest is created. The setLayout statement sets our applet's layout style:
       public void init() {
          super.init();
          setLayout(new BorderLayout()); 
  5. Create an instance of the HOD Environment object, passing the applet instance. The HOD Environment class needs the applet instance when HOD beans run as an applet:
          Environment env = new Environment(this);
  6. Create a Properties object to be used to set some initial bean property values. Each entry in the Properties object is a pair of strings; the first string is the name of the property and the second string is its value. Bean properties that are not specified in the Properties object are initialized to their default values when the bean is constructed:
          try {
             Properties p = new Properties();
             // Add some Terminal bean properties 

    You can set the host name to a valid telnet server and start the host connection. In this next statement, you would replace "myHost" with the name of your telnet server.

             p.put(Session.HOST, "myHost");
             p.put(Session.SESSION_TYPE, ECLSession.SESSION_TYPE_3270_STR);
             p.put(Session.CODE_PAGE, ECLSession.SESSION_CODE_PAGE_DEFAULT);
             p.put(Screen.SCREEN_3D, "false");
    
             // Add some KeyPad bean properties
             p.put(KeyPad.SHAPE, KeyPad.S2X11);
  7. Create new instances of the Terminal and KeyPad beans; pass the Properties object we created earlier to each of the beans constructors:
             myTerm = new Terminal(p);   // Build a Terminal bean
             myPad = new KeyPad(p);      // Build a KeyPad bean 
  8. Add the Terminal bean as a SendKeyEvent listener on the KeyPad bean. This means that any SendKeyEvents generated by the KeyPad bean will be sent to the Terminal bean's SendKey method for processing. A SendKeyEvent is generated by the keypad whenever the user clicks on a KeyPad button:
             myPad.addSendKeyListener(myTerm); 
  9. Add KeyPad as PropertyChangeListener on Terminal. This notifies the KeyPad bean of changes to Terminal properties. KeyPad will change the buttons displayed based on the terminal session type and codepage:
             myTerm.addPropertyChangeListener(myPad); 
  10. Add the beans to our applet and start communication:
             add("Center", myTerm);
             add("South", myPad);
    
             System.out.println("Starting communications to myhost...");
             myTerm.startCommunication(); 
             validate();
          } catch (Exception e) {
             e.printStackTrace();
          }
       }
    }
    

Here is the whole program, without the editorial comments:

   import com.ibm.eNetwork.beans.HOD.*;        // Get the Host Access Beans
   import com.ibm.eNetwork.ECL.ECLSession;     // Get the ECLSession constants
   import com.ibm.eNetwork.HOD.common.*;       // Get the Environment class
   import java.applet.*;                       // Get Applet class
   import java.awt.*;                          // Get the Color and Frame classes
   import java.util.*;                         // Get Properties

   public class TermTest extends Applet {
      Terminal myTerm;
      KeyPad myPad; 
      public void init() {
         super.init();                       // Call init on the super class
         setLayout(new BorderLayout());
         // Set up HOD Environment with applet instance
         Environment env = new Environment(this);

         // These constructors also accept a properties object that
         // contains all the configuration data for each bean.
         // Customization can also be done at runtime through each
         // bean's customizer class.

         try {
            Properties p = new Properties();
            // Instead of "myHost" you would put the name of your telnet server
            p.put(Session.HOST, "myHost");
            p.put(Session.SESSION_TYPE, ECLSession.SESSION_TYPE_3270_STR);
            p.put(Session.CODE_PAGE, ECLSession.SESSION_CODE_PAGE_DEFAULT);
            p.put(Screen.SCREEN_3D, "false");

            // Add some KeyPad bean properties
            p.put(KeyPad.SHAPE, KeyPad.S2X11);

            myTerm = new Terminal(p);        // Build a Terminal bean
            myPad = new KeyPad(p);           // Build a KeyPad bean

            // Add the Terminal bean as a SendKeyEvent listener on the KeyPad bean.
            // This means that any SendKeyEvents generated by the KeyPad bean will
            // be sent to the Terminal bean's SendKey method for processing.  A
            // SendKeyEvent is generated by the keypad whenever the user clicks on
            // a KeyPad button.
            myPad.addSendKeyListener(myTerm);

            // Add KeyPad as PropertyChangeListener on Terminal. This notifies the
            // KeyPad bean of changes to Terminal properties.  KeyPad will change
            // the buttons displayed based on the Terminal session type and codepage.
            myTerm.addPropertyChangeListener(myPad);

            add("Center", myTerm);
            add("South", myPad);

            System.out.println("Starting communications to myhost...");
            myTerm.startCommunication();

            validate();
         } catch (Exception e) {
            e.printStackTrace();
         }
      } // end init method
   } // end TermTest class 

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

  <HTML>
  <HEAD>
  <TITLE>First Host Access Beans Applet</TITLE>
  </HEAD>
  <BODY>
  <APPLET CODE="TermTest.class" WIDTH=600 HEIGHT=700>
  </APPLET>
  </BODY>
  </HTML>

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

    appletviewer TermTest.html

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