关于JAVA 小应用程序的问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 03:13:45
编写一个APPLET程序,使其在窗口中以红黄和蓝循环显示以下内容: Applet Progtam
写的程序最好加注解 而且最后少点 呵呵

先用画图画出这几个字
颜色用随即函数Radom来设置
再在线程中调用repaint()方法就可以画出来.

package test;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

public class BlinkingText extends Applet implements Runnable {

public BlinkingText() {
super();
init();
}

/**
* 初始化
*/
public void init() {
this.setSize(300,200);
font = new Font("TimesRoman", 0, 24);
speed = 1000;
color = 0;
lbl = "Applet Program";
}

public void start()
{
blinker = new Thread(this);
blinker.start();
}

public void run() {
do {
try {
Thread.currentThread();
Thread.sleep(speed);
}
catch(InterruptedException e) { }
repaint();
} while(true);
}

/**
* 绘画函数
*/
public void paint(Graphics