📄 gatuttextcrawler.java
字号:
//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;
//构造函数
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;
}
//画屏函数
public void paint(Graphics g)
{
}
//更新屏幕函数
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);
}
}
//启动小程序
public void start()
{
crawler = new Thread(this);
crawler.start();
}
//停止小程序
public void stop()
{
crawler.stop();
}
//运行小程序
public void run()
{
while(crawler != null)
{
try
{
Thread.currentThread();
Thread.sleep(speed);
}
catch(InterruptedException _ex) { }
repaint();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -