applet求助!

来源:百度知道 编辑:UC知道 时间:2024/06/20 22:05:18
这里有两个applet程序的paint方法和run方法
public void run() {
Thread me = Thread.currentThread();
while (runner == me) {
try {
Thread.sleep(100);
synchronized(this) {
while (threadSuspended) {
wait();
}
}
} catch (InterruptedException e){
}
repaint();
}
}

public void paint(Graphics g) {
int length = bannerChars.length;
for (int i = 0, x = 0; i < length; i++) {
int wd, ht;
if (attributes[i] == '^') {
wd = SMALL_WD;
ht = SMALL_HT;
g.setFont(smallFont);
} else {
wd = REGULAR_WD;
ht = REGULAR_HT;
g.setFont(regularFont);
}
int px = (int) (10 * Math.random() + x);
int py = (int) (10 *

private class ThreadOne extends Thread{

//TODO: 将第一个run及paint方法copy到这里

}

private class ThreadTwo extends Thread{

//TODO: 将第二个run及paint方法copy到这里

}

然后在Applet方法里启动上面两个线程:
ThreadOne threadOne = new ThreadOne ();
threadOne.start();
ThreadTwo threadTwo = new ThreadTwo ();
threadTwo.start();

2个run方法可以定义为2个类
2个paint(Graphics g)内容直接叠起来,注意变量问题就可以了