I am currently working on an intro screen for a game designed using JOGL. I want the intro to be a JPanel with a few buttons to alter options before starting the game.
我目前正在为使用JOGL设计的游戏制作一个介绍屏幕。我希望这个简介是一个JPanel,带有几个按钮,可以在开始游戏之前改变选项。
So, I have JFrame which I add a GLCanvas to. The GLCanvas also contains a GLEventListener. Finally, I add the JPanel.
所以,我有JFrame,我添加了一个GLCanvas。 GLCanvas还包含一个GLEventListener。最后,我添加了JPanel。
I have overridden the JPanel paintComponent method to set a background image. I have a few buttons within the panel. Whenever you click the 'play' button, it calls a function which does:
我已经覆盖了JPanel paintComponent方法来设置背景图像。我在面板中有几个按钮。每当您单击“播放”按钮时,它会调用一个函数:
frame.remove(JPanel); frame.repaint(); animator.start();
frame.remove(JPanel的); frame.repaint(); animator.start();
What happens is that my JPanel goes away correctly, but when repaint is called, my frame is just filled with grey. I know that the animator is starting correctly as the display method in my GLEventListener is getting called.
发生的事情是我的JPanel正确消失了,但是当重新调用时,我的框架只是用灰色填充。我知道动画师正在启动,因为我的GLEventListener中的显示方法被调用。
Does anyone know what the problem is there?
有谁知道那里有什么问题?
1 个解决方案
#1
What is your LayoutManager? If you didn't specify one, then by adding the JPanel you replace the GLCanvas.
什么是LayoutManager?如果您没有指定一个,那么通过添加JPanel,您可以替换GLCanvas。
I would make your code do this:
frame.remove(JPanel); frame.add(glcanvas); animator.start();
you may need to throw in a frame.revalidate(). I'm not up on how all that works right now.
我会让你的代码执行此操作:frame.remove(JPanel); frame.add(GLCanvas中); animator.start();你可能需要抛出一个frame.revalidate()。我现在还不清楚它是如何运作的。
#1
What is your LayoutManager? If you didn't specify one, then by adding the JPanel you replace the GLCanvas.
什么是LayoutManager?如果您没有指定一个,那么通过添加JPanel,您可以替换GLCanvas。
I would make your code do this:
frame.remove(JPanel); frame.add(glcanvas); animator.start();
you may need to throw in a frame.revalidate(). I'm not up on how all that works right now.
我会让你的代码执行此操作:frame.remove(JPanel); frame.add(GLCanvas中); animator.start();你可能需要抛出一个frame.revalidate()。我现在还不清楚它是如何运作的。