开发者社区> 问答> 正文

java程序出现Exception in thread "main" java.?报错

java程序出现Exception in thread "main" java.lang.Error: Unresolved compilation problem: at src.TankClient.main(TankClient.java:46)? 400 报错  import java.awt.;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


import javax.swing.
;
public class TankClient extends Frame{
public static final int GAME_WIDTH = 800;
public static final int GAME_HEIGH = 600;
//坦克圆 
int x = 50,y = 50;
Image offScreenImage = null;
public void paint(Graphics g){
 
g.setColor(Color.RED);
g.fillOval(x,y,30,30);
y+=2;
  }//重写update方法消除闪烁
public void update(Graphics g) {
if(offScreenImage == null){
offScreenImage = this.createImage(GAME_WIDTH,GAME_HEIGH);
}
Graphics goffScreen = offScreenImage.getGraphics();
Color c = goffScreen.getColor();
goffScreen.setColor(Color.GREEN);
goffScreen.fillRect(0,0,GAME_WIDTH,GAME_HEIGH);
paint(goffScreen);
g.drawImage(offScreenImage,0,0,null);
goffScreen.setColor(c);
}
//窗口设置
public void lauchFrame(){
this.setLocation(400,300);
this.setSize(GAME_WIDTH,GAME_HEIGH);
this.addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e){
System.exit(0);
}
});
this.setResizable(false);
this.setBackground(Color.GREEN);
setVisible(true);
PaintThread p = new PaintThread();
Thread t = new Thread(p);
t.start();
}//主方法
     public static void main(String[] args){
TankClient tc = new TankClient();
tc.lauchFrame();
 
}//启动线程另坦克圆动起来
     private class PaintThread implements Runnable{
    public void run(){
    while(true){
    repaint();
    try{
    Thread.sleep(100);
    }catch(InterruptedException e){
    e.printStackTrace();
    }
    }
    }
     }


}


展开
收起
优选2 2020-06-09 15:28:55 1029 0
1 条回答
写回答
取消 提交回答
  • 精于基础,广于工具,熟于业务。

    和之前的重复了。

    2020-06-12 10:35:50
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载