到底要不要加main()函数,要是要加,应该在哪加??急求大侠们帮小弟看看这道有关Java中的主线程题,编译后有问题,我之后加了个测试类,还是不行,我想了好几天都不会,小弟在此感激不尽!!!
import java.applet.*;
import java.awt.*;
public class Example2 extends java.applet.Applet implements Runnable{
Thread circleThread;
public void start(){
if(circleThread==null){
circleThread=new Thread(this);
circleThread.start();
}
}
public void run(){
while(circleThread!=null){
repaint();
try{
circleThread.sleep(1000);
}catch(InterruptedException e){
System.out.println(e);
}
}
}
public void paint(Graphics g){
double i=Math.random();
if(i<0.5)
g.setColor(Color.red);
else
g.setColor(Color.blue);
}
public void stop(){
circleThread.yield();
circleThread=null;
}
}
/*class Test{ //这是我之后写的测试类。
public static void main(String[]args){
Example2 exam=new Example2();
exam.start();
}
}*/