我想写个applet程序,显示两个不停变换颜色的字符,我的基本思想是用双线程,每个线程各自完成各自的字符显示,但程序编译有万多个错误,我看不懂,找不出原因,求教育,3q。 //<applet code=test.class width=200 height=200>
//</applet>
import javax.swing.*; //不晓得要用那些,所以全写了。 import java.applet.*; import java.awt.*; import java.net.*; import java.applet.Applet; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.text.*; import java.util.*;
public class test extends Applet { public void paint(Graphics g) { Font f1=new Font("TimesRoman",Font.BOLD+Font.ITALIC,25); g.setFont(f1); Draw1() { g.setColor(Color.black); g.drawString("Test1",30,70); g.setColor(Color.red); g.drawString("Test1",30,70); g.setColor(Color.blue); g.drawString("Test1",30,70); g.setColor(Color.green); g.drawString("Test1",30,70); }
Draw2() { g.setColor(Color.black); g.drawString("Test2",30,150); g.setColor(Color.red); g.drawString("Test2",30,150); g.setColor(Color.blue); g.drawString("Test2",30,150); g.setColor(Color.green); g.drawString("Test2",30,150); }
class T1 extends Thread { public void run() { do { Draw1(); }while(true); } } T1 T1Create() { T1 b=new T1(); return b; } class T2 extends Thread { public void run() { do { Draw2(); }while(true); } }
T2 T2Create() { T2 b=new T2(); return b; } t=new test(); t1=t.T1Create(); t2=t.T2Create(); t1.setPriority(Thread.MAX_PRIORITY); t2.setPriority(Thread.MIN_PRIORITY); t1.start(); t2.start(); } }