【发布时间】:2014-08-04 19:11:25
【问题描述】:
如何在小程序中的 JPanel 之间切换?在 JFrame 中的 JPanel 之间切换非常容易,我这样做是这样的:
frame.remove(mainMenu); //remove the old jpanel
frame.add(game); //add the new jpanel
game.createImage(); //runs createVolatileImage(width, height)
//in the other class (JPanel)
frame.revalidate();
frame.repaint();
requestFocus();
但是,如何在小程序中复制它?当我在小程序中尝试此操作时,当我尝试在新 JPanel 中创建的图像上运行 image.getGraphics() 时,会收到 nullPointerException。
【问题讨论】:
标签: java swing applet jpanel japplet