1个回答
展开全部
代码。
--------------------------------------------
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class AppletDemo extends Applet {
Color[] colors = { Color.RED, Color.GREEN, Color.BLUE };
int index = 0;
public void init() {
super.init();
setSize(200, 200);
Timer timer = new Timer();
timer.schedule(new ColorChange(), new Date(), 500);
}
public void paint(Graphics g) {
super.paint(g);
if (index == colors.length) {
index = 0;
}
Color color = colors[index++];
g.setColor(color);
g.drawString("hello", 10, 10);
g.drawString("Color", 10, 30);
g.drawString("wait", 10, 50);
}
class ColorChange extends TimerTask {
public void run() {
repaint();
}
}
}
--------------------------------------------
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class AppletDemo extends Applet {
Color[] colors = { Color.RED, Color.GREEN, Color.BLUE };
int index = 0;
public void init() {
super.init();
setSize(200, 200);
Timer timer = new Timer();
timer.schedule(new ColorChange(), new Date(), 500);
}
public void paint(Graphics g) {
super.paint(g);
if (index == colors.length) {
index = 0;
}
Color color = colors[index++];
g.setColor(color);
g.drawString("hello", 10, 10);
g.drawString("Color", 10, 30);
g.drawString("wait", 10, 50);
}
class ColorChange extends TimerTask {
public void run() {
repaint();
}
}
}
更多追问追答
追问
能够详细点给我写一下timer时间代码的解释么?我第一次看timer事件。,好多不懂。。刚刚我试了一下运行。。无法运行
追答
奇怪了,你是怎么拷的代码,我这没有问题啊.
timer不是一个事件,是一个定进任务,在指定的时间点,执行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询