//***************************************
//* Class name: RHL2 *
//* §@ªÌ: Michael Hsin *
//* ª©¥»: 1.00 *
//* Update: 04/04/1997 *
//***************************************
//°Ñ¼Æ:
// MessageNumber: ¾ã¼Æ¡AMessageªº¼Æ¥Ø
// Message1, Message2 ...: ¦r¦ê¡AMessages
// FontSize: ¾ã¼Æ¡A¦r«¬ªº¤j¤p
// FontName: ¦r¦ê¡A¦r«¬ªº¦WºÙ
// FontItalic: true©Î¬Ofalse¡A¬O§_n±×
// FontBold: true©Î¬Ofalse¡A¬O§_n²Ê
// FontRed: ¾ã¼Æ \
// FontGreen: ¾ã¼Æ |---¦r«¬ªºÃC¦
// FontBlue: ¾ã¼Æ /
// BackRed: ¾ã¼Æ \
// BackGreen: ¾ã¼Æ |---I´ºªºÃC¦
// BackBlue: ¾ã¼Æ /
// Width: ¾ã¼Æ¡Aapplet¦ûªº¼e«×
// Height: ¾ã¼Æ¡Aapplet¦ûªº°ª«×
// LoopDelay: ¾ã¼Æ¡A¨C¦¸«Ã¸©µ¿ðªº®É¶¡¡A³æ¦ì¬O²@¬í¡]¤d¤À¤§¤@¬í¡^
// LoopStep: ¾ã¼Æ¡A¨C¦¸«Ã¸©Ò²¾°Êªº¶ZÂ÷¡]ÂI¡^
//import section
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.lang.Math;
//end import section
public class RHL2 extends java.applet.Applet implements Runnable
{
Thread ChCTh = null; //multi thread¥Î
String temp; //tempÀ´¶Ü¡H
FontMetrics MyFontM; //FontMetrics¡A¨ú±oFont¸Ô²Ó¸ê®Æ¥Îª
Font MyFont; //°µ¤@Ó¦Û¤vªºFont
int a; //°j°éÅܼÆ
int currentMessage = 0; //¥Ø«eMessageªº½s
int currentCount = 0; //¥Ø«eMessageÅã¥Üªº¦ì¸m
int MessageWidth; //MessageÅã¥Ü©Ò»Ýªº¼e«×
int FontType = Font.PLAIN; //Fontªº«¬¦¡¡A¹w³]¬O¤@¯ë¦r«¬
//input parameter *****
int MessageNumber = 2; //Messageªº¼Æ¥Ø
String Message[] = {"Michael Hsin's JAVA applet", "Ho Ho Ho"};
int FontSize = 24; //
String FontName = "Arial"; //
boolean FontItalic = false; //
boolean FontBold = true; //
int FontRed = 255; //
int FontGreen = 255; //
int FontBlue = 0; //³o¨Ç¤£¥Î¸ÑÄÀ¤F§a
int BackRed = 192; //
int BackGreen = 192; //
int BackBlue = 192; //
int Width = 500; //
int Height = 300; //
Color FontColor; //
Color BackColor; //
int LoopDelay = 200; //¨C¦¸«Ã¸©µ¿ðªº®É¶
//³æ¦ì¬O²@¬í¡]¤d¤À¤§¤@¬í¡^
int LoopStep = 1; //¨C¦¸«Ã¸©Ò²¾°Êªº¶ZÂ÷¡]ÂI¡^
//input parameter *****
public void start()
{
temp = getParameter("MessageNumber");
if(temp != null)
{
MessageNumber = Integer.parseInt(temp);
Message = new String[MessageNumber];
for(a = 0;a < MessageNumber;a ++)
{
temp = getParameter("Message" + Integer.toString(a + 1));
if(temp != null)
Message[a] = temp;
}
}
temp = getParameter("FontName");
if(temp != null)
FontName = temp;
temp = getParameter("FontItalic");
if(temp != null)
{
temp = temp.toLowerCase();
if(temp.equals("true"))
FontItalic = true;
}
temp = getParameter("FontBold");
if(temp == null)
{
temp = temp.toLowerCase();
if(temp.equals("true"))
FontBold = true;
}
FontType = (FontItalic ? 1 : 0) * Font.ITALIC +
(FontBold ? 1 : 0) * Font.BOLD ;
temp = getParameter("FontSize");
if(temp != null)
FontSize = Integer.parseInt(temp);
MyFont = new Font(FontName,FontType,FontSize);
temp = getParameter("Width");
if(temp != null)
Width = Integer.parseInt(temp);
temp = getParameter("Height");
if(temp != null)
Height = Integer.parseInt(temp);
resize(Width, Height);
temp = getParameter("LoopDelay");
if(temp != null)
LoopDelay = Integer.parseInt(temp);
temp = getParameter("LoopStep");
if(temp != null)
LoopStep = Integer.parseInt(temp);
temp = getParameter("FontRed");
if(temp != null)
FontRed = Integer.parseInt(temp);
temp = getParameter("FontGreen");
if(temp != null)
FontGreen = Integer.parseInt(temp);
temp = getParameter("FontBlue");
if(temp != null)
FontBlue = Integer.parseInt(temp);
FontColor = new Color(FontRed,FontGreen,FontBlue);
temp = getParameter("BackRed");
if(temp != null)
BackRed = Integer.parseInt(temp);
temp = getParameter("BackGreen");
if(temp != null)
BackGreen = Integer.parseInt(temp);
temp = getParameter("BackBlue");
if(temp != null)
BackBlue = Integer.parseInt(temp);
BackColor = new Color(BackRed,BackGreen,BackBlue);
if(ChCTh == null)
{
ChCTh = new Thread(this);
ChCTh.start();
}
}
public void stop()
{
ChCTh.stop();
ChCTh = null;
}
public void run()
{
while(true)
{
try { Thread.sleep(LoopDelay); }
catch (InterruptedException e) {}
repaint();
}
}
public void paint(Graphics g)
{
g.setFont(MyFont);
MyFontM = g.getFontMetrics();
MessageWidth = MyFontM.stringWidth(Message[currentMessage]);
g.setColor(BackColor);
g.fillRect(0, 0, Width, Height);
g.setColor(FontColor);
g.drawString(Message[currentMessage], Width - currentCount, (Height + MyFontM.getAscent()) / 2);
currentCount += LoopStep;
if(currentCount >= Width + MessageWidth)
currentMessage ++;
currentMessage %= MessageNumber;
currentCount %= (Width + MessageWidth);
}
public void update(Graphics g)
{
paint(g);
}
}