Java如何在浏览器状态栏中显示消息?
在此applet示例中,您将看到如何在浏览器状态栏中显示消息。为了使示例更加有趣,我们将当前时间显示为消息。该时间将在小应用程序的生命周期中每秒更新一次。
package org.nhooo.example.applet;
import java.applet.Applet;
import java.awt.Graphics;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TimeApplet extends Applet implements Runnable {
private DateFormat formatter = null;
private Thread t = null;
public void init() {
formatter = new SimpleDateFormat("hh:mm:ss");
t = new Thread(this);
}
public void start() {
t.start();
}
public void stop() {
t = null;
}
public void paint(Graphics g) {
Date now = Calendar.getInstance().getTime();
//在浏览器状态栏上显示当前时间
this.showStatus(formatter.format(now));
}
public void run() {
int delay = 1000;
try {
while (t == Thread.currentThread()) {
//每秒重新绘制小程序
repaint();
Thread.sleep(delay);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练