如何清除/重置 JFrame

发布于 2024-11-14 08:18:47 字数 639 浏览 3 评论 0原文

我和我的朋友决定开发一款在 3 个屏幕(Player1HandScreen、Player2HandScreen 和 FightScreen)之间循环的纸牌游戏。

一旦玩家1从Player1HandScreen中选择了他们的牌,Player1HandScreen就会引导到Player2HandScreen,而玩家2也会做同样的事情。然后 Player2HandScreen 引导至 FightScreen,其中两张牌进行比较,并宣布一名玩家成为该轮的获胜者。

我们遇到的问题是,一旦回合结束,我们想要清除Player1HandScreen以及Player2HandScreen,一旦刷新我们的参数,我们就很难成功更新GUI。

我们尝试过使用 removeAll(),但无法将其使用 repaint()validate()

我们还研究了 super.paintComponents(g)updateUI(),但两者都让我们的希望和梦想破灭了。

Me and my friend have decided to work on a card game which cycles between 3 screens (Player1HandScreen, Player2HandScreen and FightScreen).

Once Player1 has chosen their card from Player1HandScreen, Player1HandScreen leads to Player2HandScreen where Player2 does the same. then Player2HandScreen leads to FightScreen where the two cards are compared and one player is declared the winner of that round.

The problem we are having is that once the round ends we want to clear Player1HandScreen as well as the Player2HandScreen once refreshing our parameters we are having trouble updating the GUI successfully.

We have have tried to use removeAll(), but we can't get it to repaint() or validate().

We have also looked into super.paintComponents(g) and updateUI() but both have left us with crushed hopes and dreams.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏大泽ㄣ 2024-11-21 08:18:47

如果您从容器中删除任何 JComponent(仅最后一次),则需要告诉容器,

removeAll()//or remove(JComponent)
revalidate();
repaint();

if you remove any JComponent(s) from Container (only once on the end), is needed tell to Container for,

removeAll()//or remove(JComponent)
revalidate();
repaint();
遥远的她 2024-11-21 08:18:47

尝试使用以下方法清除 Jpanel:

paper.clearRect(0, 0, (int)panel.getSize().getWidth(), (int)panel.getSize().getHeight

其中 paper 类似于:Graphics paper = panel.getGraphics();

Try to clear you Jpanel using:

paper.clearRect(0, 0, (int)panel.getSize().getWidth(), (int)panel.getSize().getHeight

where paper is something like: Graphics paper = panel.getGraphics();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文