我在Java中制作了一款游戏,在Eclipse中运行时没有任何问题。一切看起来都很棒,而且它是有效的完成的(至少在我想出了一些与之相关的东西之前)。所以我一直试图把它放在我的网站上,但是每当我在浏览器中运行游戏时,我只会看到一个白色屏幕,尽管检查Java控制台显示没有错误。我设法将问题缩小到屏幕的绘画。我有一个计时器来运行游戏,并让事情发生。在它的最后,它调用repaint()方法。在Eclipse中,工作正常,但在浏览器中,没有任何反应。
这里是相关的代码(所有这些都在名为FinalProject的主类中):
public class FinalProject extends JApplet implements ActionListener,
KeyListener, MouseListener, MouseMotionListener {
public void init(){
//...initialize program
System.out.println("game started");
}
/**
* A method called every so often by a timer to control the game world.
* Mainly calls other functions to control objects directly, but this
* is used as the only timer, which also calls repaint() at it's end.
*/
private void runGame(){
//...Run game and do important stuff
//This Draws The Screen
System.out.println("about to paint");
repaint();
}
public void paint(Graphics g){
System.out.println("painting");
//...paint screen
}
public void update(Graphics gr){
System.out.println("updating");
paint(gr);
}
}runGame()由计时器调用。在Eclipse中,输出是:
游戏开始
绘画点击
绘画点击
即将画画
绘画点击
即将画画
绘画点击
即将画画
绘画点击
...
在浏览器中执行此操作时(直接在我的机器上离线运行,所有浏览器也有同样的问题),控制台显示:
...(加载的东西)
游戏开始
基本:Applet初始化
基本:启动小程序
基本:完成全面汇总 -
基本:Applet使可见
基本:Applet开始
基本:告诉客户端小程序开始
即将画画
即将画画
即将画画
...
在这一点上我不知道还有什么可以尝试的。尽管我努力,但我仍然不完全明白repaint()做了什么,我只知道它最终调用update()和paint()。除了这在浏览器中似乎没有发生。我正在使用Windows 7 64x与Java版本7更新5.预先感谢任何帮助。