Files
Work/java/COUNTER/Led.java
2024-08-07 09:16:27 -04:00

111 lines
4.3 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 Led extends Thread
{
private Thread mThread=null;
private InFile mInFile;
private final int smImageCount=12;
private Image[] mLedImages=new Image[smImageCount];
private String mStrParam=null;
private java.applet.Applet mApplet=null;
private final int TimeOut=300000;
Led(java.applet.Applet applet)
{
init(applet);
}
public void init(java.applet.Applet applet)
{
mApplet=applet;
mLedImages[0]=mApplet.getImage(mApplet.getCodeBase(),"image/zero.gif");
mLedImages[1]=mApplet.getImage(mApplet.getCodeBase(),"image/one.gif");
mLedImages[2]=mApplet.getImage(mApplet.getCodeBase(),"image/two.gif");
mLedImages[3]=mApplet.getImage(mApplet.getCodeBase(),"image/three.gif");
mLedImages[4]=mApplet.getImage(mApplet.getCodeBase(),"image/four.gif");
mLedImages[5]=mApplet.getImage(mApplet.getCodeBase(),"image/five.gif");
mLedImages[6]=mApplet.getImage(mApplet.getCodeBase(),"image/six.gif");
mLedImages[7]=mApplet.getImage(mApplet.getCodeBase(),"image/seven.gif");
mLedImages[8]=mApplet.getImage(mApplet.getCodeBase(),"image/eight.gif");
mLedImages[9]=mApplet.getImage(mApplet.getCodeBase(),"image/nine.gif");
mLedImages[10]=mApplet.getImage(mApplet.getCodeBase(),"image/dash.gif");
mLedImages[11]=mApplet.getImage(mApplet.getCodeBase(),"image/blank.gif");
MediaTracker mediaTracker=new MediaTracker(mApplet);
for(int imageIndex=0;imageIndex<smImageCount;imageIndex++)mediaTracker.addImage(mLedImages[imageIndex],imageIndex);
try{mediaTracker.waitForAll();}
catch(InterruptedException exception){;}
}
public void run()
{
while(true)
{
mStrParam=new String("......");
try{mInFile=new InFile(mApplet.getCodeBase(),"log/access.cnt");}
catch(Exception exception){continue;}
if(mInFile.isOkay())
{
try{mStrParam=new String(mInFile.readLine());}
catch(Exception exception){;}
}
mInFile.close();
mApplet.repaint();
try {sleep(TimeOut);}
catch(InterruptedException exception){break;}
mStrParam=new String("......");
mApplet.repaint();
}
}
public void paint(Graphics graphics)
{
drawLEDString(mStrParam,graphics);
}
private void drawLEDString(String strLED,Graphics graphics)
{
int strLength=strLED.length();
int imageWidth;
int imageHeight;
Point ptLoc;
if(null==mStrParam)return;
ptLoc=new Point(4,4);
imageWidth=mLedImages[0].getWidth(mApplet);
imageHeight=mLedImages[0].getHeight(mApplet);
for(int strIndex=0;strIndex<strLength;strIndex++)
{
char strChar=strLED.charAt(strIndex);
if('0'==strChar)graphics.drawImage(mLedImages[0],ptLoc.x,ptLoc.y,mApplet);
else if('1'==strChar)graphics.drawImage(mLedImages[1],ptLoc.x,ptLoc.y,mApplet);
else if('2'==strChar)graphics.drawImage(mLedImages[2],ptLoc.x,ptLoc.y,mApplet);
else if('3'==strChar)graphics.drawImage(mLedImages[3],ptLoc.x,ptLoc.y,mApplet);
else if('4'==strChar)graphics.drawImage(mLedImages[4],ptLoc.x,ptLoc.y,mApplet);
else if('5'==strChar)graphics.drawImage(mLedImages[5],ptLoc.x,ptLoc.y,mApplet);
else if('6'==strChar)graphics.drawImage(mLedImages[6],ptLoc.x,ptLoc.y,mApplet);
else if('7'==strChar)graphics.drawImage(mLedImages[7],ptLoc.x,ptLoc.y,mApplet);
else if('8'==strChar)graphics.drawImage(mLedImages[8],ptLoc.x,ptLoc.y,mApplet);
else if('9'==strChar)graphics.drawImage(mLedImages[9],ptLoc.x,ptLoc.y,mApplet);
else if('.'==strChar)graphics.drawImage(mLedImages[10],ptLoc.x,ptLoc.y,mApplet);
else graphics.drawImage(mLedImages[11],ptLoc.x,ptLoc.y,mApplet);
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);
}
}