如何清除/重置JFrame [英] How to clear/ reset a JFrame
问题描述
我和我的朋友决定开展一个在3个屏幕之间循环的纸牌游戏( Player1HandScreen,Player2HandScreen和FightScreen )。
Me and my friend have decided to work on a card game which cycles between 3 screens (Player1HandScreen, Player2HandScreen and FightScreen).
一旦Player1从 Player1HandScreen
中选择了他们的卡, Player1HandScreen
导致 Player2HandScreen
其中Player2也是如此。然后 Player2HandScreen
导致 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.
我们遇到的问题是,一旦结束,我们要清除 Player1HandScreen
以及 Player2HandScreen
刷新我们的参数后,我们无法成功更新GUI。
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.
我们已尝试使用 removeAll()
,但我们无法将其转换为 repaint()
或 validate()
。
We have have tried to use removeAll()
, but we can't get it to repaint()
or validate()
.
我们还调查了 super.paintComponents(g)
和 updateUI()
但两者都给我们留下了希望和梦想。
We have also looked into super.paintComponents(g)
and updateUI()
but both have left us with crushed hopes and dreams.
推荐答案
如果你删除来自Container的任何JComponent(只有一次),需要告诉Container,
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();
这篇关于如何清除/重置JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!