SampleApplication
Programmable Host On-Demand
Display session sample application
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();
/*
* For this sample, we are assuming files created by the Deployment Wizard
* are in c:\MyApplication\demo\HODData\sample1 directory
*
* Therefore, I need to create a File object to c:\MyApplication\demo directory.
*/
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);
}
}
Sample application explanation
The following explains each statement or group of statements used in this sample program. Only those statements that involve the Programmable Host On-Demand API are explained.
- Import the necessary packages as follows:
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.*;
- Create a simple Java class called Sample which extends JFrame:
public class Sample extends JFrame { - Create instance variables.
JMenuBar menuBar = new JMenuBar(); CustomDesktop desktop = null; HODDisplaySession session = null; - Create the HODSessionManager and CustomDesktop objects. You should create
only one HODSessionManager object and only one CustomDesktop object.
HODSessionManager sm = new HODSessionManager(); /* * For this sample, we are assuming files created by the Deployment Wizard * are in c:\MyApplication\demo\HODData\sample1 directory * * Therefore, I need to create a File object to c:\MyApplication\demo directory * and when I create the CustomDesktop object, I pass in "sample1" to tell the * API to look in the "sample1" directory under HODData. */ try { File file = new File("c:\\MyApplication\\demo"); desktop = sm.createCustomDesktop(this, file, "sample1"); } catch (Exception e) { } - Start a 3270 session and add it to the 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) {} }
Run the sample application
To run Sample1, save the sample program in a file called Sample1.java and compile it. You can run the the application by executing the following command:
java -classpath .;hoddbg2.jar;hacp.jar;ha_en.jar;hodimg.jar Sample1
[ Top of Page | Previous Page | Next Page | Table of Contents ]