如何在每次循环再次开始时清除面板?如果我在品牌面板上输入“hersheys”并在产品面板上输入“chocolate”然后按回车键,“hersheys”和“chocolate”这个词仍然存在。如何清除?
import javax.swing.*;
public class Test {
public static void main(String[] args) {
JTextField f1 = new JTextField(5);
JTextField f2 = new JTextField(5);
JPanel myPanel = new JPanel();
myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS));
myPanel.add(new JLabel("Brand:"));
myPanel.add(f1);
myPanel.add(new JLabel("Product:"));
myPanel.add(f2);
for(int i=0;i<2;i++){
int result = JOptionPane.showConfirmDialog(null, myPanel,
"Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION);
}
}
}