当前位置: 代码迷 >> J2SE >> java中定义enum枚举门类报错,望高手指教
  详细解决方案

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

热度:4648   发布时间:2013-02-25 00:00:00.0
java中定义enum枚举类型报错,望高手指教
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


------解决方案--------------------------------------------------------
jdk版本问题
  相关解决方案