我看到这个视频[10:00] 开始用 Java 创建一个 2d 游戏,我尝试使用他在视频中使用的代码,但我得到了错误,我不知道如何修复他。
package me.Kenig.game2d;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
public static final int WIDTH = 160;
public static final int HEIGHT = WIDTH/12*9;
public static final int SCALE = 3;
public static final String NAME = "Game";
private JFrame frame; // error
public Game(){
setMinimumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
setMaximumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
setPreferredSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // error
@Override
public void run() {
// TODO Auto-generated method stub
}
}