Programmable Host On-Demand 解説書

Programmable Host On-Demand

表示セッション・サンプル・アプリケーション

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;

import com.ibm.eNetwork.HOD.customizable.*;
import com.ibm.eNetwork.beans.HOD.*;

public class Sample1 extends JFrame {


    JMenuBar menuBar = new JMenuBar();
    CustomDesktop desktop = null;
    HODDisplaySession session = null;

    public static void main(String[] args)
    {
        new Sample1().run();
    }

    private Sample1()
    {
    }

    void run()
    {

        HODSessionManager sm = new HODSessionManager();

        /*
         * このサンプルでは、デプロイメント・ウィザードによって作成されるファイルの位置は
         * c:\MyApplication\demo\HODData\sample1 ディレクトリーと仮定しています。
         *
         * したがって、File オブジェクトは c:\MyApplication\demo ディレクトリーに作成する必要があります。
         */

        try {

            File file = new File("c:\\MyApplication\\demo");
            desktop = sm.createCustomDesktop(this, file, "sample1");

        } catch (Exception e) { }

        buildMenus();
        setJMenuBar(menuBar);
        if (desktop != null) createTerminal();

        addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    myExit();
                }
        });

        Toolkit toolkit = this.getToolkit();
        Dimension screenSize = toolkit.getScreenSize();

        this.setSize(screenSize.width*2/3, screenSize.height*2/3);

        this.setLocation( (screenSize.width-getWidth()) / 2, (screenSize.height-getHeight()) / 2 );

        show();
    }

    void buildMenus()
    {

        JMenu menu = new JMenu("File");
        JMenuItem menuItem = new JMenuItem("Exit");
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    myExit();
                }
        });
        menuBar.add(menu);
    }

    void createTerminal()
    {

        try {
            session = desktop.startDisplaySession("3270 Display");
            if (session != null) {
               this.getContentPane().add(session.getTerminal());

               JMenu menu = new JMenu("HOD Session");
               menuBar.add(menu);

               JMenuBar hodMenuBar = session.getHODMenubar();
               MenuElement[] menuElements = hodMenuBar.getSubElements();
               int count = hodMenuBar.getMenuCount();
               for (int i = 0; i < menuElements.length; i++) {
                  menu.add((JMenu)menuElements[i]);
               }
            }
        } catch (Exception e) {
        }
    }

    void myExit()
    {
        if (desktop != null) {
            desktop.closeAllSessions();
        }
        System.exit(0);
    }
}

サンプル・アプリケーションの説明

このサンプル・プログラムで使用されている各ステートメントまたはステートメントのグループを以下に説明します。 ここでは、Programmable Host On-Demand API に関係したステートメントのみを説明します。

  1. 必要なパッケージを次のようにインポートします。
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.io.File;
      import com.ibm.eNetwork.HOD.customizable.*;
      import com.ibm.eNetwork.beans.HOD.*;
      
  2. JFrame を拡張する Sample というシンプルな Java クラスを作成します。
     public class Sample extends JFrame { 
  3. インスタンス変数を作成します。
            JMenuBar menuBar = new JMenuBar();
            CustomDesktop desktop = null;
            HODDisplaySession session = null;
      
  4. HODSessionManager オブジェクトと CustomDesktop オブジェクトを作成します。 HODSessionManager オブジェクトと CustomDesktop オブジェクトは、それぞれ 1 つのみ作成してください。
            HODSessionManager sm = new HODSessionManager();
    
            /*
             * このサンプルでは、デプロイメント・ウィザードによって作成されるファイルの位置は
             * c:\MyApplication\demo\HODData\sample1 ディレクトリーと仮定しています。
             *
             * したがって、File オブジェクトは c:\MyApplication\demo ディレクトリーに作成する必要があり、
             * CustomDesktop オブジェクトを作成するときは、"sample1" を渡して
             * HODData の下の "sample1" ディレクトリーを探すよう API に指示します。
             */
    
            try {
    
                File file = new File("c:\\MyApplication\\demo");
                desktop = sm.createCustomDesktop(this, file, "sample1");
    
            } catch (Exception e) { }
      
  5. 3270 セッションを開始し、それを JFrame に追加します。
            void createTerminal()
            {
    
              try {
                session = desktop.startDisplaySession("3270 Display");
                if (session != null) {
                   this.getContentPane().add(session.getTerminal());
    
                   JMenu menu = new JMenu("HOD Session");
                   menuBar.add(menu);
    
                   JMenuBar hodMenuBar = session.getHODMenubar();
                   MenuElement[] menuElements = hodMenuBar.getSubElements();
                   int count = hodMenuBar.getMenuCount();
                   for (int i = 0; i < menuElements.length; i++) {
                        menu.add((JMenu)menuElements[i]);
                   }
                }
    
              } catch (Exception e) {}
            }
    
      

サンプル・アプリケーションの実行

Sample1 を実行するには、サンプル・プログラムを Sample1.java というファイルに保存し、それをコンパイルします。 次のコマンドを実行することにより、アプリケーションを実行できます。

    java -classpath .;hoddbg2.jar;hacp.jar;ha_en.jar;hodimg.jar Sample1

[ ページの先頭 | 直前のページ | 次のページ | 目次 ]