到底要不要加main()函数,要是要加,应该在哪加??急求大侠们帮小弟看看这道有关Java中的主线程题,编译后有问题,我之后加了个测试类,还是不行,我想了好几天都不会,小弟在此感激不尽!!!

oegeooegeo 2009-03-31 01:34:59
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();
}
}*/
...全文
106 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxgamexx 2009-04-02
  • 打赏
  • 举报
回复
/*class Test{ //这是我之后写的测试类。
public static void main(String[]args){
Example2 exam=new Example2();
exam.start();
}
}*/

去掉class Test

直接写void main() 式试
chenliuyang 2009-03-31
  • 打赏
  • 举报
回复
先把circlethread=null;
在把当前线程停了看看
public void stop(){
circleThread=null;
circleThread.yield();

}
chenliuyang 2009-03-31
  • 打赏
  • 举报
回复
public void stop(){
circleThread.yield();
circleThread=null; //这一句一直都不会执行吧,假如STOP一次那你的程序就不会动了
}

25,980

社区成员

发帖
与我相关
我的任务
社区描述
高性能WEB开发
社区管理员
  • 高性能WEB开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧