【发布时间】:2012-06-17 22:13:12
【问题描述】:
public void paint (Graphics g)
{
bufferGraphics.setColor (Color.black);
bufferGraphics.clearRect (0, 0, dim.width, dim.width);
while (input != KeyEvent.VK_SPACE)
{
bufferGraphics.fillRect (0, 0, dim.width, dim.height);
}
bufferGraphics.drawImage (track, 0, 0, dim.width, dim.height, this);
bufferGraphics.setFont (new Font ("Calibri", Font.PLAIN, 25));
bufferGraphics.drawString ("Level: " + level, 30, 30);
bufferGraphics.drawImage (car, 620, myCarY, 70, 120, this);
bufferGraphics.drawImage (opponent, 415, oppCarY, 70, 120, this);
move ();
这是现在的代码。执行时,我得到一个冻结的空白窗口,甚至无法关闭。
【问题讨论】:
-
您是否打算将“false”的值分配给“run”?
-
是的,我是初学者,对不起
-
试一试:while (!run) { ...} 语句“run = false”将“false”的值赋给“run”。
-
为什么你的 keyReleased 分配 Unicode 为空?尝试像其他人一样将其设为
e.getChar(),除非有特定原因。 -
如果这样做,程序会卡在 for 循环中
标签: java applet keylistener event-listener