我正在尝试开始一些二维代码,到目前为止我有这么多。它应该只是出现一个窗口,但是当我运行它(在调试中)时,我收到一条错误消息,提示找不到源?有人看到我错过了什么吗?
package game;
import java.awt.BorderLayout;
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 = "My Game";
private JFrame frame;
public boolean running=false;
public Game()
{
setMinimumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
setMaximumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
setPreferredSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
frame = new JFrame(NAME);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(this,BorderLayout.CENTER);
frame.pack();
frame.setResizable(false);
frame.setLocation(null);
frame.setVisible(true);
}
public synchronized void start()
{
running = true;
new Thread(this).start();
}
public synchronized void stop()
{
running =false;
}
public void run()
{
while(running)
{
System.out.println("Hello!");
}
}
public static void main(String[]args)
{
new Game().start();
}
}
我正在从一些教程中得到这个,我自己经历了几次代码,但我无法发现什么是错的。:(