java中定义enum枚举类型报错,望高手指教

无意摘花
博客专家认证
2009-06-29 08:23:17
package com.kksoft.test;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

enum Dir {
left, right
}

public class TankClient extends Frame {

int x = 0;
int y = 50;
int i=0;
Dir dir=Dir.left;

public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.RED);
if(dir == Dir.left) {
x-=10;
if(x<=0) {
dir = Dir.right;
}
} else {
x+=10;
if(x>=200) {
dir = Dir.left;
}
}
g.fillOval(x, y, 30, 30);
g.setColor(c);

// if(i<=1600){
// x=Math.abs(800-i);i+=20;
// }




}

public void lauchFrame() {
this.setLocation(400, 300);
this.setSize(800, 600);
this.setTitle("TankWar");
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setResizable(false);
this.setBackground(Color.GREEN);
setVisible(true);

new Thread(new PaintThread()).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();
}
}
}

}

}
上面这个程序在同学的电脑上调试好了 可到我电脑上无法运行,出现以下错误:
标记“enum”上有语法错误,应为 interface
...全文
1106 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wyystc 2011-01-03
  • 打赏
  • 举报
回复
怎么看jdk的版本啊?
无意摘花 2009-06-29
  • 打赏
  • 举报
回复
谢谢 已经找到原因了 改成6.0就行了
knightzhuwei 2009-06-29
  • 打赏
  • 举报
回复
jdk版本问题

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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