如何清除/重置 JFrame
我和我的朋友决定开发一款在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您从容器中删除任何 JComponent(仅最后一次),则需要告诉容器,
if you remove any JComponent(s) from Container (only once on the end), is needed tell to Container for,
尝试使用以下方法清除 Jpanel:
其中 paper 类似于:
Graphics paper = panel.getGraphics();
Try to clear you Jpanel using:
where paper is something like:
Graphics paper = panel.getGraphics();