Appendix B
TMS15_Frame
//TMS-15 Client Program for logging onto TMS-15 via Till_Link program
//18/02/2000 Stephen Wilkinson
//
/*
This simple extension of the java.awt.Frame class
contains all the elements necessary to act as the
main window of an application.
*/
import java.awt.*;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.util.*;
import java.lang.*;
import symantec.itools.db.awt.TextArea;
public class TMS15_Frame extends Frame
{
/* creates the various static data
* @param ASCII array holds all the ascii values
* @param EBCDIC array holds all the ebcdic values
* @param BufferSize integer holds the buffer size
* @param Version string holds the version number
* @param EndOfMessage integer holds the control character value
*/
// buffer size for socket connection
final static int BufferSize = 2048;
// version number of software
final static String Version = "1.0";
// ascii end of message code
final static int EndOfMessage = 4;
// array of ascii codes
final static int ASCII [] = { 0, 1, 2, 3, 0, 9, 0, 127, 0, 0, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 0, 8, 0, 24, 25, 0, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 10,
23, 27, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 22, 0, 0, 0, 0, 4, 0, 0, 0, 0, 20, 21, 0, 26, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 91, 46,
60, 40, 43, 93, 38, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 36, 42, 41, 59, 94, 45, 47, 32, 32, 32, 32, 32, 32, 32, 32, 124, 44, 37,
95, 62, 63, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96, 58, 35, 64, 39, 61, 34, 32, 97, 98, 99, 100, 101, 102, 103, 104, 105, 32, 32, 32,
32, 32, 32, 32, 106, 107, 108, 109, 110, 111, 112, 113, 114, 32, 32, 32, 32, 32, 32, 32, 126, 115, 116, 117, 118, 119, 120, 121, 122,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, 32,
32, 32, 32, 32, 32, 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, 32, 32, 32, 32, 32, 32, 92, 32, 83, 84, 85, 86, 87, 88, 89, 90, 32, 32,
32, 32, 32, 32, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 32, 32, 32, 32, 32, 32 };
// array of ebcdic codes
final static int EBCDIC [] = { 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, 64, 90, 127,
123, 91, 108, 80, 125, 77, 93, 92, 78, 107, 96, 75, 97, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 122, 94, 76, 126, 110, 111,
124, 193, 194, 195, 196, 197, 198, 199, 200, 201, 209, 210, 211, 212, 213, 214, 215, 216, 217, 226, 227, 228, 229, 230, 231, 232, 233,
75, 224, 75, 95, 109, 96, 129, 130, 131, 132, 133, 134, 135, 136, 137, 145, 146, 147, 148, 149, 150, 151, 152, 153, 162, 163, 164, 165,
166, 167, 168, 169, 192, 106, 208, 161, 7, 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, 16, 17, 18, 19, 60, 61, 50, 38, 24,
25, 63, 39, 28, 29, 30, 31, 64, 90, 127, 123, 91, 108, 80, 125, 77, 93, 92, 78, 107, 96, 75, 97, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 122, 94, 76, 126, 110, 111, 124, 193, 194, 195, 196, 197, 198, 199, 200, 201, 209, 210, 211, 212, 213, 214, 215, 216, 217, 226,
227, 228, 229, 230, 231, 232, 233, 75, 224, 75, 95, 109, 96, 129, 130, 131, 132, 133, 134, 135, 136, 137, 145, 146, 147, 148, 149, 150, 151,
152, 153, 162, 163, 164, 165, 166, 167, 168, 169, 192, 106, 208, 161, 7 };
public TMS15_Frame()
{
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setSize(405,305);
setVisible(false);
openFileDialog1.setMode(FileDialog.LOAD);
openFileDialog1.setTitle("Open");
//$$ openFileDialog1.move(24,312);
logonBtn.setLabel("log on to TMS15");
add(logonBtn);
logonBtn.setBackground(java.awt.Color.lightGray);
logonBtn.setBounds(144,108,108,40);
display.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.TEXT_CURSOR));
add(display);
display.setBounds(60,24,288,72);
setTitle("AWT Application");
//}}
//{{INIT_MENUS
menu1.setLabel("File");
menu1.add(newMenuItem);
newMenuItem.setLabel("New");
newMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_N,false));
menu1.add(openMenuItem);
openMenuItem.setLabel("Open...");
openMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_O,false));
menu1.add(saveMenuItem);
saveMenuItem.setLabel("Save");
saveMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_S,false));
menu1.add(saveAsMenuItem);
saveAsMenuItem.setLabel("Save As...");
menu1.add(separatorMenuItem);
separatorMenuItem.setLabel("-");
menu1.add(exitMenuItem);
exitMenuItem.setLabel("Exit");
mainMenuBar.add(menu1);
menu2.setLabel("Edit");
menu2.add(cutMenuItem);
cutMenuItem.setLabel("Cut");
cutMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_X,false));
menu2.add(copyMenuItem);
copyMenuItem.setLabel("Copy");
copyMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_C,false));
menu2.add(pasteMenuItem);
pasteMenuItem.setLabel("Paste");
pasteMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_V,false));
mainMenuBar.add(menu2);
menu3.setLabel("Help");
menu3.add(aboutMenuItem);
aboutMenuItem.setLabel("About...");
mainMenuBar.add(menu3);
//$$ mainMenuBar.move(0,312);
setMenuBar(mainMenuBar);
//}}
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
openMenuItem.addActionListener(lSymAction);
exitMenuItem.addActionListener(lSymAction);
aboutMenuItem.addActionListener(lSymAction);
SymMouse aSymMouse = new SymMouse();
logonBtn.addMouseListener(aSymMouse);
this.addMouseListener(aSymMouse);
//}}
}
public TMS15_Frame(String title)
{
this();
setTitle(title);
}
/**
* Shows or hides the component depending on the boolean flag b.
* @param b if true, show the component; otherwise, hide the component.
* @see java.awt.Component#isVisible
*/
public void setVisible(boolean b)
{
if(b)
{
setLocation(50, 50);
}
super.setVisible(b);
}
static public void main(String args[])
{
try
{
//Create a new instance of our application's frame, and make it visible.
(new TMS15_Frame()).setVisible(true);
}
catch (Throwable t)
{
System.err.println(t);
t.printStackTrace();
//Ensure the application exits with an error condition.
System.exit(1);
}
}
public void addNotify()
{
// Record the size of the window prior to calling parents addNotify.
Dimension d = getSize();
super.addNotify();
if (fComponentsAdjusted)
return;
// Adjust components according to the insets
setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
Component components[] = getComponents();
for (int i = 0; i < components.length; i++)
{
Point p = components[i].getLocation();
p.translate(getInsets().left, getInsets().top);
components[i].setLocation(p);
}
fComponentsAdjusted = true;
}
// Used for addNotify check.
boolean fComponentsAdjusted = false;
//{{DECLARE_CONTROLS
java.awt.FileDialog openFileDialog1 = new java.awt.FileDialog(this);
java.awt.Button logonBtn = new java.awt.Button();
symantec.itools.db.awt.TextArea display = new symantec.itools.db.awt.TextArea();
//}}
//{{DECLARE_MENUS
java.awt.MenuBar mainMenuBar = new java.awt.MenuBar();
java.awt.Menu menu1 = new java.awt.Menu();
java.awt.MenuItem newMenuItem = new java.awt.MenuItem();
java.awt.MenuItem openMenuItem = new java.awt.MenuItem();
java.awt.MenuItem saveMenuItem = new java.awt.MenuItem();
java.awt.MenuItem saveAsMenuItem = new java.awt.MenuItem();
java.awt.MenuItem separatorMenuItem = new java.awt.MenuItem();
java.awt.MenuItem exitMenuItem = new java.awt.MenuItem();
java.awt.Menu menu2 = new java.awt.Menu();
java.awt.MenuItem cutMenuItem = new java.awt.MenuItem();
java.awt.MenuItem copyMenuItem = new java.awt.MenuItem();
java.awt.MenuItem pasteMenuItem = new java.awt.MenuItem();
java.awt.Menu menu3 = new java.awt.Menu();
java.awt.MenuItem aboutMenuItem = new java.awt.MenuItem();
//}}
class SymWindow extends java.awt.event.WindowAdapter
{
public void windowClosing(java.awt.event.WindowEvent event)
{
Object object = event.getSource();
if (object == TMS15_Frame.this)
TMS15_Frame_WindowClosing(event);
}
}
void TMS15_Frame_WindowClosing(java.awt.event.WindowEvent event)
{
// to do: code goes here.
TMS15_Frame_WindowClosing_Interaction1(event);
}
void TMS15_Frame_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
{
try {
// QuitDialog Create and show as modal
(new TMS15_QuitDialog(this, true)).setVisible(true);
} catch (Exception e) {
}
}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == openMenuItem)
openMenuItem_ActionPerformed(event);
else if (object == aboutMenuItem)
aboutMenuItem_ActionPerformed(event);
else if (object == exitMenuItem)
exitMenuItem_ActionPerformed(event);
}
}
void openMenuItem_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
openMenuItem_ActionPerformed_Interaction1(event);
}
void openMenuItem_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
// OpenFileDialog Create and show as modal
int defMode = openFileDialog1.getMode();
String defTitle = openFileDialog1.getTitle();
String defDirectory = openFileDialog1.getDirectory();
String defFile = openFileDialog1.getFile();
openFileDialog1 = new java.awt.FileDialog(this, defTitle, defMode);
openFileDialog1.setDirectory(defDirectory);
openFileDialog1.setFile(defFile);
openFileDialog1.setVisible(true);
} catch (Exception e) {
}
}
void aboutMenuItem_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
aboutMenuItem_ActionPerformed_Interaction1(event);
}
void aboutMenuItem_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
// AboutDialog Create and show as modal
(new TMS15_AboutDialog(this, true)).setVisible(true);
} catch (Exception e) {
}
}
void exitMenuItem_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
exitMenuItem_ActionPerformed_Interaction1(event);
}
void exitMenuItem_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
// QuitDialog Create and show as modal
(new TMS15_QuitDialog(this, true)).setVisible(true);
} catch (Exception e) {
}
}
class SymMouse extends java.awt.event.MouseAdapter
{
public void mouseClicked(java.awt.event.MouseEvent event)
{
Object object = event.getSource();
if (object == logonBtn)
logonBtn_MouseClicked(event);
}
}
void logonBtn_MouseClicked(java.awt.event.MouseEvent event)
{
/* creates a socket connection to the Till_Link software, sends the data to log on
* and gets confirmation back from the till and displays it.
* @param server server socket for getting and sending data
* @param connection the connection to the server socket
* @param output the output stream to send data to the Till_Link
* @param fileInput the input stream from the Till_Link
* @param character used for reading the data from the byte array
* @param conversion used when converting between ascii/ebcdic etc.
* @param request string that holds data being read from or written to
* @param b byte array that stream is written to
* @param ch character used for getting the value of a character
* @param count used for all looping
*/
// server socket for connection to Till_Link socket
ServerSocket server;
// socket for connection to Till_Link server socket
Socket connection;
// output stream to send data to Till_Link server socket
OutputStream output;
// input stream for data from Till_Link socket
DataInputStream fileInput;
// integer for reading data from byte array
int character = 0;
// integer for converting ascii to ebcdic and vice versa
int conversion = 0;
// string data is read into or wrote from
String request;
// array of bytes that stream is read into
byte [] b = new byte [BufferSize];
// used for getting character value (has to be set to a character when instantiated)
Character ch = new Character('a');
// makes request a new string
request = new String();
// sets all data in byte array to 0
for(int count = 0; count < BufferSize; count++) {
b[count] = 0;
}
try {
// makes a connection to the Till_Link software running on Hex on port 5000
connection = new Socket("Hex", 5000);
// creates an output stream linked to this connection
output = connection.getOutputStream();
// creates a string to be sent to the TMS-15
String s = new String("452079");
// goes through the string converting ascii to ebcdic and sending it to the Till_Link program
for (int i = 0; i < s.length(); i++){
// gets value of the character at a position in the string
ch = new Character((char)s.charAt(i));
// sets the value of conversion to the value of that character
conversion = ch.charValue();
// goes through the ascii array finding the value of the conversion and sending the value
// at the equivelent position in the ebcdic array
for(int count = 0; count < ASCII.length; count++){
if(ASCII[count] == conversion){
// writes the ebcdic to the stream
output.write((char)EBCDIC[count]);
// this just displays each value on the display screen within TMS-15
display.appendText(" A: " + Integer.toString(ASCII[count]));
display.appendText(" E: " + Integer.toString(EBCDIC[count]));
// jumps out and looks at the next value in the string being sent
break;
}
}
// outputs the end of message value
output.write((char)4);
}
// outputs the end of message value
output.write((char)EndOfMessage);
// creates an input stream linked to the socket connection
InputStream input = new BufferedInputStream(connection.getInputStream());
// while there is still data being sent
while(character != 4) {
// gets each character from the input stream
character = input.read();
// if an invalid character..
if(character == -1){
return;
}else{
// ch becomes the character from the input stream
ch = new Character((char)character);
// sets conversion to the value of ch
conversion = ch.charValue();
// goes through ebcdic array, compares the value and dislays the character sent from Till_Link
for(int count = 0; count < EBCDIC.length; count++){
if(EBCDIC[count] == conversion){
display.appendText(" A: " + Integer.toString(ASCII[count]));
break;
}
}
}
}
// closes the connection
connection.close();
}catch(IOException e) {
// gets any errors when connection is attempted
e.printStackTrace();
}
}
}
Back to Contents
Back to Home Page
TMS15_AboutDialog
/*
A basic extension of the java.awt.Dialog class
*/
import java.awt.*;
public class TMS15_AboutDialog extends Dialog {
public TMS15_AboutDialog(Frame parent, boolean modal)
{
super(parent, modal);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setSize(249,150);
setVisible(false);
label1.setText("A Basic Java Application");
add(label1);
label1.setBounds(40,35,166,21);
okButton.setLabel("OK");
add(okButton);
okButton.setBounds(95,85,66,27);
setTitle("AWT Application - About");
//}}
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
okButton.addActionListener(lSymAction);
//}}
}
public TMS15_AboutDialog(Frame parent, String title, boolean modal)
{
this(parent, modal);
setTitle(title);
}
public void addNotify()
{
// Record the size of the window prior to calling parents addNotify.
Dimension d = getSize();
super.addNotify();
// Only do this once.
if (fComponentsAdjusted)
return;
// Adjust components according to the insets
Insets insets = getInsets();
setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
Component components[] = getComponents();
for (int i = 0; i < components.length; i++)
{
Point p = components[i].getLocation();
p.translate(insets.left, insets.top);
components[i].setLocation(p);
}
// Used for addNotify check.
fComponentsAdjusted = true;
}
public void setVisible(boolean b)
{
if (b)
{
Rectangle bounds = getParent().getBounds();
Rectangle abounds = getBounds();
setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
bounds.y + (bounds.height - abounds.height)/2);
}
super.setVisible(b);
}
//{{DECLARE_CONTROLS
java.awt.Label label1 = new java.awt.Label();
java.awt.Button okButton = new java.awt.Button();
//}}
// Used for addNotify check.
boolean fComponentsAdjusted = false;
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == okButton)
okButton_ActionPerformed(event);
}
}
void okButton_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
okButton_ActionPerformed_Interaction1(event);
}
void okButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
this.dispose();
} catch (Exception e) {
}
}
class SymWindow extends java.awt.event.WindowAdapter
{
public void windowClosing(java.awt.event.WindowEvent event)
{
Object object = event.getSource();
if (object == TMS15_AboutDialog.this)
TMS15_AboutDialog_WindowClosing(event);
}
}
void TMS15_AboutDialog_WindowClosing(java.awt.event.WindowEvent event)
{
// to do: code goes here.
TMS15_AboutDialog_WindowClosing_Interaction1(event);
}
void TMS15_AboutDialog_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
{
try {
this.dispose();
} catch (Exception e) {
}
}
}
Back to Contents
Back to Home Page
TMS15_QuitDialog
/*
A basic extension of the java.awt.Dialog class
*/
import java.awt.*;
import java.awt.event.*;
public class TMS15_QuitDialog extends Dialog
{
public TMS15_QuitDialog(Frame parent, boolean modal)
{
super(parent, modal);
//Keep a local reference to the invoking frame
frame = parent;
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setSize(337,135);
setVisible(false);
yesButton.setLabel(" Yes ");
add(yesButton);
yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
yesButton.setBounds(72,80,79,22);
noButton.setLabel(" No ");
add(noButton);
noButton.setFont(new Font("Dialog", Font.BOLD, 12));
noButton.setBounds(185,80,79,22);
label1.setText("Do you really want to exit?");
label1.setAlignment(java.awt.Label.CENTER);
add(label1);
label1.setBounds(78,33,180,23);
setTitle("AWT Application - Exit");
//}}
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
noButton.addActionListener(lSymAction);
yesButton.addActionListener(lSymAction);
//}}
}
public void addNotify()
{
// Record the size of the window prior to calling parents addNotify.
Dimension d = getSize();
super.addNotify();
if (fComponentsAdjusted)
return;
// Adjust components according to the insets
setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
Component components[] = getComponents();
for (int i = 0; i < components.length; i++)
{
Point p = components[i].getLocation();
p.translate(getInsets().left, getInsets().top);
components[i].setLocation(p);
}
fComponentsAdjusted = true;
}
public TMS15_QuitDialog(Frame parent, String title, boolean modal)
{
this(parent, modal);
setTitle(title);
}
/**
* Shows or hides the component depending on the boolean flag b.
* @param b if true, show the component; otherwise, hide the component.
* @see java.awt.Component#isVisible
*/
public void setVisible(boolean b)
{
if(b)
{
Rectangle bounds = getParent().getBounds();
Rectangle abounds = getBounds();
setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
bounds.y + (bounds.height - abounds.height)/2);
Toolkit.getDefaultToolkit().beep();
}
super.setVisible(b);
}
// Used for addNotify check.
boolean fComponentsAdjusted = false;
// Invoking frame
Frame frame = null;
//{{DECLARE_CONTROLS
java.awt.Button yesButton = new java.awt.Button();
java.awt.Button noButton = new java.awt.Button();
java.awt.Label label1 = new java.awt.Label();
//}}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == yesButton)
yesButton_ActionPerformed(event);
else if (object == noButton)
noButton_ActionPerformed(event);
}
}
void yesButton_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
yesButton_ActionPerformed_Interaction1(event);
}
void yesButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
frame.setVisible(false); // Hide the invoking frame
frame.dispose(); // Free system resources
this.dispose(); // Free system resources
System.exit(0); // close the application
} catch (Exception e) {
}
}
void noButton_ActionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
noButton_ActionPerformed_Interaction1(event);
}
void noButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
this.dispose();
} catch (Exception e) {
}
}
class SymWindow extends java.awt.event.WindowAdapter
{
public void windowClosing(java.awt.event.WindowEvent event)
{
Object object = event.getSource();
if (object == TMS15_QuitDialog.this)
TMS15_QuitDialog_WindowClosing(event);
}
}
void TMS15_QuitDialog_WindowClosing(java.awt.event.WindowEvent event)
{
// to do: code goes here.
TMS15_QuitDialog_WindowClosing_Interaction1(event);
}
void TMS15_QuitDialog_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
{
try {
this.dispose();
} catch (Exception e) {
}
}
}
Back to Contents