142 lines
4.9 KiB
Java
142 lines
4.9 KiB
Java
import java.awt.*;
|
|
import java.awt.Font;
|
|
import java.awt.Graphics;
|
|
import java.awt.Color;
|
|
import java.util.Date;
|
|
import java.awt.Frame;
|
|
import java.awt.image.*;
|
|
import java.io.*;
|
|
import java.net.*;
|
|
|
|
public class HotLink extends java.applet.Applet implements Runnable
|
|
{
|
|
private Thread mThread;
|
|
private final int smImageCount=12;
|
|
private Image[] mLedImages=new Image[smImageCount];
|
|
private String mStrServerIP;
|
|
// private String mURLString;
|
|
private Button mHTTPButton;
|
|
private Button mTelnetButton;
|
|
private final int mTimeout=60000;
|
|
private final String mHTTPButtonLabel=new String("Ganymede (HTTP)");
|
|
private final String mTelnetButtonLabel=new String("Ganymede (TELNET)");
|
|
|
|
public HotLink()
|
|
{
|
|
}
|
|
public void init()
|
|
{
|
|
mHTTPButton=new Button(mHTTPButtonLabel);
|
|
mTelnetButton=new Button(mTelnetButtonLabel);
|
|
add(mHTTPButton);
|
|
add(mTelnetButton);
|
|
mLedImages[0]=getImage(getCodeBase(),"image/zero.gif");
|
|
mLedImages[1]=getImage(getCodeBase(),"image/one.gif");
|
|
mLedImages[2]=getImage(getCodeBase(),"image/two.gif");
|
|
mLedImages[3]=getImage(getCodeBase(),"image/three.gif");
|
|
mLedImages[4]=getImage(getCodeBase(),"image/four.gif");
|
|
mLedImages[5]=getImage(getCodeBase(),"image/five.gif");
|
|
mLedImages[6]=getImage(getCodeBase(),"image/six.gif");
|
|
mLedImages[7]=getImage(getCodeBase(),"image/seven.gif");
|
|
mLedImages[8]=getImage(getCodeBase(),"image/eight.gif");
|
|
mLedImages[9]=getImage(getCodeBase(),"image/nine.gif");
|
|
mLedImages[10]=getImage(getCodeBase(),"image/dash.gif");
|
|
mLedImages[11]=getImage(getCodeBase(),"image/blank.gif");
|
|
MediaTracker mediaTracker=new MediaTracker(this);
|
|
for(int imageIndex=0;imageIndex<smImageCount;imageIndex++)mediaTracker.addImage(mLedImages[imageIndex],imageIndex);
|
|
try(mediaTracker.waitForAll());
|
|
catch(InterruptedException exception){;}
|
|
repaint();
|
|
}
|
|
public void run()
|
|
{
|
|
while(null!=mThread)
|
|
{
|
|
LocalServer localServer;
|
|
localServer=new LocalServer();
|
|
try{mStrServerIP=localServer.getServerIP(getCodeBase());}
|
|
catch(Exception exception){mStrServerIP=new String("255.255.255.255");}
|
|
// mURLString=new String("http://");
|
|
// mURLString+=mStrServerIP;
|
|
repaint();
|
|
try{mThread.sleep(mTimeout);}
|
|
catch(InterruptedException exception){break;}
|
|
}
|
|
}
|
|
public void start()
|
|
{
|
|
if(mThread==null){mThread=new Thread(this);mThread.start();}
|
|
}
|
|
public void stop()
|
|
{
|
|
if(null!=mThread){mThread.stop();mThread=null;}
|
|
}
|
|
public void update(Graphics graphics)
|
|
{
|
|
paint(graphics);
|
|
}
|
|
public void paint(Graphics graphics)
|
|
{
|
|
setBackground(new Color(0x2A,0x7F,0xAA));
|
|
drawLEDString(mStrServerIP,graphics);
|
|
}
|
|
public void drawLEDString(String strLED,Graphics graphics)
|
|
{
|
|
int strLength=strLED.length();
|
|
int imageWidth;
|
|
int imageHeight;
|
|
Point ptLoc;
|
|
|
|
ptLoc=new Point(4,4);
|
|
imageWidth=mLedImages[0].getWidth(this);
|
|
imageHeight=mLedImages[0].getHeight(this);
|
|
for(int strIndex=0;strIndex<strLength;strIndex++)
|
|
{
|
|
char strChar=strLED.charAt(strIndex);
|
|
|
|
if('0'==strChar)graphics.drawImage(mLedImages[0],ptLoc.x,ptLoc.y,this);
|
|
else if('1'==strChar)graphics.drawImage(mLedImages[1],ptLoc.x,ptLoc.y,this);
|
|
else if('2'==strChar)graphics.drawImage(mLedImages[2],ptLoc.x,ptLoc.y,this);
|
|
else if('3'==strChar)graphics.drawImage(mLedImages[3],ptLoc.x,ptLoc.y,this);
|
|
else if('4'==strChar)graphics.drawImage(mLedImages[4],ptLoc.x,ptLoc.y,this);
|
|
else if('5'==strChar)graphics.drawImage(mLedImages[5],ptLoc.x,ptLoc.y,this);
|
|
else if('6'==strChar)graphics.drawImage(mLedImages[6],ptLoc.x,ptLoc.y,this);
|
|
else if('7'==strChar)graphics.drawImage(mLedImages[7],ptLoc.x,ptLoc.y,this);
|
|
else if('8'==strChar)graphics.drawImage(mLedImages[8],ptLoc.x,ptLoc.y,this);
|
|
else if('9'==strChar)graphics.drawImage(mLedImages[9],ptLoc.x,ptLoc.y,this);
|
|
else if('.'==strChar)graphics.drawImage(mLedImages[10],ptLoc.x,ptLoc.y,this);
|
|
else graphics.drawImage(mLedImages[11],ptLoc.x,ptLoc.y,this);
|
|
ptLoc.x+=imageWidth;
|
|
}
|
|
graphics.setColor(new Color(48,64,0));
|
|
graphics.drawLine(3,3,ptLoc.x,3);
|
|
graphics.drawLine(3,3,3,imageHeight+4);
|
|
graphics.setColor(new Color(175,192,224));
|
|
graphics.drawLine(3,imageHeight+4,ptLoc.x,imageHeight+4);
|
|
graphics.drawLine(ptLoc.x,3,ptLoc.x,imageHeight+4);
|
|
graphics.setColor(new Color(96,143,208));
|
|
graphics.drawRect(2,2,(ptLoc.x+1)-2,imageHeight+3);
|
|
graphics.setColor(new Color(175,192,224));
|
|
graphics.drawLine(1,1,ptLoc.x+2,1);
|
|
}
|
|
public boolean action(Event event,Object object)
|
|
{
|
|
if(null!=mHTTPButton&&mHTTPButton==event.target)
|
|
{
|
|
URL localLink;
|
|
try{localLink=new URL("http://"+mStrServerIP);};
|
|
catch(MalformedURLException exception){return true;}
|
|
getAppletContext().showDocument(localLink);
|
|
}
|
|
else if(null!=mTelnetButton&&mTelnetButton==event.target)
|
|
{
|
|
URL localLink;
|
|
try{localLink=new URL("telnet:"+mStrServerIP);}
|
|
catch(MalformedURLException exception){return true;}
|
|
getAppletContext().showDocument(localLink);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|