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 に関係したステートメントのみを説明します。
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 Sample extends JFrame {
JMenuBar menuBar = new JMenuBar();
CustomDesktop desktop = null;
HODDisplaySession session = null;
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) { }
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