?? gatuttextcrawler.java
字號(hào):
//GatutTextCrawler.java
import java.applet.Applet;
import java.awt.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class GatutTextCrawler extends Applet implements Runnable {
//變量定義
Dimension d = null;
Font font = null;
FontMetrics fm = null;
Thread crawler = null;
String msgText = null,
fontName = null,
adds = null;
int speed = 0,
fontSize = 0,
leftLimit = 0,
y = 0,
x = 0;
//構(gòu)造函數(shù)
public GatutTextCrawler()
{
}
//初始化小程序
public void init()
{
String s;
try
{
adds = InetAddress.getLocalHost().toString();
}
catch(UnknownHostException _ex)
{
adds = "unknown";
}
s = getParameter("fontSize");
fontSize = s != null ? Integer.valueOf(s).intValue() : 12;
s = getParameter("fontName");
fontName = s != null ? s : "TimesRoman";
font = new Font(fontName, 0, fontSize);
try
{
speed = 100/Integer.valueOf(getParameter("speed"))
.intValue();
}
catch(Exception _ex)
{
speed = 100;
}
msgText = getParameter("preText") + adds +
getParameter("postText");
d = getSize();
y = d.height - (d.height - font.getSize()) - 2;
}
//畫(huà)屏函數(shù)
public void paint(Graphics g)
{
}
//更新屏幕函數(shù)
public void update(Graphics g)
{
if(crawler != null)
{
g.setColor(Color.black);
g.fillRect(0, 0, d.width, d.height);
g.setFont(font);
fm = g.getFontMetrics();
leftLimit = -fm.stringWidth(msgText);
x--;
if(x < leftLimit)
x = d.width;
g.setColor(Color.white);
g.drawString(msgText, x, y);
}
}
//啟動(dòng)小程序
public void start()
{
crawler = new Thread(this);
crawler.start();
}
//停止小程序
public void stop()
{
crawler.stop();
}
//運(yùn)行小程序
public void run()
{
while(crawler != null)
{
try
{
Thread.currentThread();
Thread.sleep(speed);
}
catch(InterruptedException _ex) { }
repaint();
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -