How do I make my button display at the time I want it to?

邮差的信 提交于 2019-12-02 12:09:23

Basically, I want her to be able to press the "Gather Wood" button 5 times then, right after she presses it the fifth time, the "Create Fire" button should pop up.

I don't see any "if logic" anywhere that tells the code to do anything.

Once you fix that (and verify that the "createFire()` method is invoked) I suspect the next problem is that when you add a component to a visible Swing GUI the basic code should be:

panel.add(...);
panel.revalidate();
panel.repaint();

You need the revalidate() to invoke the layout manager otherwise the added component has a size of (0, 0) and there is nothing to paint.

panel.add(fire, new FlowLayout(FlowLayout.CENTER));

Don't keep trying to change the layout manager. That is not what the second parameter is used for. The layout manager of the panel should be set only once when the panel is created.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!