import java.awt.*;
import java.awt.event.*;
public class ast01001 extends java.applet.Applet implements
ActionListener,MouseListener
// Software written by William Overington
// WOverington@ngo.globalnet.co.uk
// 6 August 2001
// Copyright 2001 William Overington
//
{
int obeycode;
int storedobeycode;
int pressx,pressy;
boolean SIMULATION_DVB_MHP_MOUSE_ATTACHED=false;
// this is what the simulation management environment knows
boolean mouseattached;
// this is what the simulated program knows
int SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline=1;
boolean SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_eof=true;
String SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_inputstring;
Button colourButton1 = new Button("");
Button colourButton2 = new Button("");
Button colourButton3 = new Button("");
Button colourButton4 = new Button("");
Button digitButton0 = new Button("0");
Button digitButton1 = new Button("1");
Button digitButton2 = new Button("2");
Button digitButton3 = new Button("3");
Button digitButton4 = new Button("4");
Button digitButton5 = new Button("5");
Button digitButton6 = new Button("6");
Button digitButton7 = new Button("7");
Button digitButton8 = new Button("8");
Button digitButton9 = new Button("9");
Button upButton = new Button("^");
Button downButton = new Button("v");
Button leftButton = new Button("<");
Button rightButton = new Button(">");
Button enterButton = new Button("E");
Button teletextButton = new Button("T");
Font buttonsfont,displayfont;
// polyglot compatibility section starts
// There are no strings to be translated for this program.
// polyglot compatibility section finishes
public void init()
{
setLayout(null);
setBounds(0,0,512,400);
buttonsfont = new Font("SansSerif", Font.PLAIN, 18);
displayfont = new Font("SansSerif", Font.PLAIN, 24);
setFont(buttonsfont);
colourButton1.addActionListener(this);
colourButton1.setLocation(16,327);
colourButton1.setSize(25,25);
colourButton1.setBackground(Color.red);
add(colourButton1);
colourButton2.addActionListener(this);
colourButton2.setLocation(48,327);
colourButton2.setSize(25,25);
colourButton2.setBackground(Color.green);
add(colourButton2);
colourButton3.addActionListener(this);
colourButton3.setLocation(80,327);
colourButton3.setSize(25,25);
colourButton3.setBackground(Color.yellow);
add(colourButton3);
colourButton4.addActionListener(this);
colourButton4.setLocation(112,327);
colourButton4.setSize(25,25);
colourButton4.setBackground(Color.blue);
add(colourButton4);
digitButton0.addActionListener(this);
digitButton0.setLocation(16,359);
digitButton0.setSize(25,25);
digitButton0.setBackground(Color.lightGray);
add(digitButton0);
digitButton1.addActionListener(this);
digitButton1.setLocation(48,359);
digitButton1.setSize(25,25);
digitButton1.setBackground(Color.lightGray);
add(digitButton1);
digitButton2.addActionListener(this);
digitButton2.setLocation(80,359);
digitButton2.setSize(25,25);
digitButton2.setBackground(Color.lightGray);
add(digitButton2);
digitButton3.addActionListener(this);
digitButton3.setLocation(112,359);
digitButton3.setSize(25,25);
digitButton3.setBackground(Color.lightGray);
add(digitButton3);
digitButton4.addActionListener(this);
digitButton4.setLocation(144,359);
digitButton4.setSize(25,25);
digitButton4.setBackground(Color.lightGray);
add(digitButton4);
digitButton5.addActionListener(this);
digitButton5.setLocation(176,359);
digitButton5.setSize(25,25);
digitButton5.setBackground(Color.lightGray);
add(digitButton5);
digitButton6.addActionListener(this);
digitButton6.setLocation(208,359);
digitButton6.setSize(25,25);
digitButton6.setBackground(Color.lightGray);
add(digitButton6);
digitButton7.addActionListener(this);
digitButton7.setLocation(240,359);
digitButton7.setSize(25,25);
digitButton7.setBackground(Color.lightGray);
add(digitButton7);
digitButton8.addActionListener(this);
digitButton8.setLocation(272,359);
digitButton8.setSize(25,25);
digitButton8.setBackground(Color.lightGray);
add(digitButton8);
digitButton9.addActionListener(this);
digitButton9.setLocation(304,359);
digitButton9.setSize(25,25);
digitButton9.setBackground(Color.lightGray);
add(digitButton9);
upButton.addActionListener(this);
upButton.setLocation(372,327);
upButton.setSize(25,25);
upButton.setBackground(Color.lightGray);
add(upButton);
downButton.addActionListener(this);
downButton.setLocation(372,359);
downButton.setSize(25,25);
downButton.setBackground(Color.lightGray);
add(downButton);
leftButton.addActionListener(this);
leftButton.setLocation(340,343);
leftButton.setSize(25,25);
leftButton.setBackground(Color.lightGray);
add(leftButton);
rightButton.addActionListener(this);
rightButton.setLocation(404,343);
rightButton.setSize(25,25);
rightButton.setBackground(Color.lightGray);
add(rightButton);
enterButton.addActionListener(this);
enterButton.setLocation(439,359);
enterButton.setSize(25,25);
enterButton.setBackground(Color.lightGray);
add(enterButton);
teletextButton.addActionListener(this);
teletextButton.setLocation(471,359);
teletextButton.setSize(25,25);
teletextButton.setBackground(Color.lightGray);
add(teletextButton);
addMouseListener(this);
setBackground(Color.black);
obeycode=1;
storedobeycode=1;
}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if (source == colourButton1)
{
obeycode=51;
repaint();
}
else
if (source == colourButton2)
{
obeycode=52;
repaint();
}
else
if (source == colourButton3)
{
obeycode=53;
repaint();
}
else
if (source == colourButton4)
{
obeycode=54;
repaint();
}
else
if (source == digitButton0)
{
obeycode=20;
repaint();
}
else
if (source == digitButton1)
{
obeycode=21;
repaint();
}
else
if (source == digitButton2)
{
obeycode=22;
repaint();
}
else
if (source == digitButton3)
{
obeycode=23;
repaint();
}
else
if (source == digitButton4)
{
obeycode=24;
repaint();
}
else
if (source == digitButton5)
{
obeycode=25;
repaint();
}
else
if (source == digitButton6)
{
obeycode=26;
repaint();
}
else
if (source == digitButton7)
{
obeycode=27;
repaint();
}
else
if (source == digitButton8)
{
obeycode=28;
repaint();
}
else
if (source == digitButton9)
{
obeycode=29;
repaint();
}
else
if (source == upButton)
{
obeycode=61;
repaint();
}
else
if (source == downButton)
{
obeycode=62;
repaint();
}
else
if (source == leftButton)
{
obeycode=63;
repaint();
}
else
if (source == rightButton)
{
obeycode=64;
repaint();
}
else
if (source == enterButton)
{
obeycode=91;
repaint();
}
else
if (source == teletextButton)
{
obeycode=92;
repaint();
}
}
public void mousePressed(MouseEvent e)
{
pressx=e.getX();
pressy=e.getY();
if ((pressy > 300) & (pressy < 311))
// then a command to the simulation environment management is intended
//
// the 300 is used in the test rather than 288 so as to give a blank area below
// the simulated display screen just in case a click intended for the bottom
// of the simulated display screen is clicked a few pixels low in error
{
if (pressx < 256) // simulated no DVB-MHP mouse
{
SIMULATION_DVB_MHP_MOUSE_ATTACHED=false;
}
else // simulated DVB-MHP mouse present
{
SIMULATION_DVB_MHP_MOUSE_ATTACHED=true;
}
obeycode=1;
repaint();
}
else if (pressy <= 287)
// then a click within the simulation on the simulated display screen is intended
{
if(SIMULATION_DVB_MHP_MOUSE_ATTACHED)
{
obeycode=41;
repaint();
}
else
{
donothing();
}
}
else
// the mouse press is on the simulated hand held infra-red control device
// or the upper part of the white area and is disregarded
{
donothing();
}
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void paint(Graphics screen)
{
storedobeycode=obeycode;
screen.setFont(displayfont);
if(obeycode != 1)
{
screen.clipRect(0,0,512,288);
}
if(obeycode == 1)
{
// start up for the simulation management
screen.setColor(Color.black);
screen.fillRect(0,0,512,288);
screen.setColor(Color.white);
screen.fillRect(0,288,512,112);
screen.setColor(Color.gray);
screen.fillRoundRect(0,311,512,89,20,20);
screen.clipRect(0,0,512,288);
// start up for the program that is being simulated
mouseattached=SIMULATION_FOR_MOUSE_getInputDeviceSupported();
//
SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_openForReading();
int count=1;
do
{
String thisstring=SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_readNextLine();
if(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_eof)
{
donothing();
}
else
{
screen.setColor(Color.cyan);
screen.drawString(thisstring,50,36*count);
count++;
}
} while (!(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_eof));
}
else
if(obeycode == 51) // red button pressed
{
donothing();
}
else if(obeycode == 52) // green button pressed
{
donothing();
}
else if(obeycode == 53) // yellow button pressed
{
donothing();
}
else if(obeycode == 54) // blue button pressed
{
donothing();
}
else if((obeycode >= 20) & (obeycode <= 29)) // a digit button pushed
{
donothing();
}
else if(obeycode == 41) // response to pressing the mouse button
{
donothing();
}
obeycode=1;
}
public void update(Graphics screen)
{
paint(screen);
}
private void donothing()
{
// does nothing
}
private boolean SIMULATION_FOR_MOUSE_getInputDeviceSupported()
{
return SIMULATION_DVB_MHP_MOUSE_ATTACHED;
}
private void SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_openForReading()
{
SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline=1;
}
private String SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_readNextLine()
{
String localinputstring;
String localchosenline="LINE0001";
// this ensures that localchosenline is always initialized
if(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline < 10)
{
String localnumberstring =
String.valueOf(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline);
localchosenline="LINE000" + localnumberstring;
}
else if(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline < 100)
{
String localnumberstring =
String.valueOf(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline);
localchosenline="LINE00" + localnumberstring;
}
else if(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline < 1000)
{
String localnumberstring =
String.valueOf(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline);
localchosenline="LINE0" + localnumberstring;
}
else if(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline < 10000)
{
String localnumberstring =
String.valueOf(SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline);
localchosenline="LINE" + localnumberstring;
}
else
{
donothing();
}
localinputstring = getParameter(localchosenline);
if (localinputstring != null)
{
if(localinputstring.equals("$$$$"))
{
SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_eof=true;
}
else
{
SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_eof=false;
}
}
else
{
localinputstring="$$$$";
SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_eof=true;
}
SIMULATION_FOR_SEQUENTIAL_TEXT_FILE_1_nextline++;
return localinputstring;
}
}