Java中的JPanel问题
你好 我在重新设置JPANEL的内容时遇到问题。是否有删除JPANEL所有内容的方法 我正在做一个刽子手游戏。我需要初始化我的面板,让位于下一个级别。我的面板是使用Netbeans GUI创建的,所有内容都是固定的(甚至位置和大小) 我的示例代码如下:Java中的JPanel问题,java,swing,jpanel,Java,Swing,Jpanel,你好 我在重新设置JPANEL的内容时遇到问题。是否有删除JPANEL所有内容的方法 我正在做一个刽子手游戏。我需要初始化我的面板,让位于下一个级别。我的面板是使用Netbeans GUI创建的,所有内容都是固定的(甚至位置和大小) 我的示例代码如下: public MainGame(JDialog owner) { super(owner, true); initComponents(); newGame(); } void
public MainGame(JDialog owner) {
super(owner, true);
initComponents();
newGame();
}
void newGame() {
jPanel3.setLayout(new GridLayout(3, 9, 3, 5));
for (char buttonChar = 'a'; buttonChar <= 'z'; buttonChar++) {
String buttonText = String.valueOf(buttonChar);
letterButton = new JButton(buttonText);
letterButton.addActionListener(this);
jPanel3.add(letterButton);
}
}
void checkHame(){
newGame(); //I CALL AGAIN TO GO TO THE NEXT LEVEL...
}
public主游戏(JDialog所有者){
超级(所有者,真实);
初始化组件();
新游戏();
}
void newGame(){
设置布局(新的网格布局(3,9,3,5));
对于(char buttonChar='a';buttonChar您可以使用removeAll
方法
<>而不是删除组件,您可以考虑将按钮的状态重置为原来的并重新使用按钮。 可以使用<代码> ReaveWALue/Cult>方法。
<>而不是删除组件,您可能只考虑将按钮的状态重置为原来的并重新使用按钮。 也可能需要调用RealValueAudio.[P>]后的RealValueAd()和RePrimeTo()。您可能需要调用RealValueAd()和RePrPrtue()removeAll之后在循环的之前执行jPanel3.removeAll()
怎么样
Removes all the components from this container.
removeAll()
的定义:-
公共无效删除所有()
在for循环之前执行jPanel3.removeAll()
怎么样
removeAll()
的定义:-
公共无效删除所有()