这是我的代码问题是我无法找到为什么要创建一个额外的表单
public void actionPerformed(ActionEvent ae){
submitBtn.setForeground(Color.red);
//getting value form the textFields
String name = nameTxt.getText();
String userName = userNameTxt.getText();
char[] pass = password.getPassword();
Object monthValue = month.getSelectedItem();
String yearValue = yearTxt.getText();
String dateValue = dateTxt.getText();
Object genderValue = gender.getSelectedItem();
String mobileValue = mobileTxt.getText();
Object locationValue = country.getSelectedItem();
showDetails page = new showDetails();
page.setVisible(true);
JPanel contentPane = new JPanel();
contentPane.setLayout(null);
contentPane.setBorder(BorderFactory.createTitledBorder("user Details"));
JLabel nameVL = new JLabel("Name : " + name );
nameVL.setBounds(80, 30, 200, 200);
contentPane.add(nameVL);
page.getContentPane().add(contentPane);
}
以上代码位于signuppage.java类
并创建一个表单以将标签结果显示到showDetails类
public class showDetails extends JFrame {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
public showDetails() {
JFrame showFrame = new JFrame("user details");
showFrame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
showFrame.setSize(300, 400);
showFrame.setVisible(true);
showFrame.setLocation((screen.width - 500)/2,((screen.height-350)/2));
}
}
但是我的问题是结果是没有在showFram中显示这个表单被创建不知道如何....
答案 0 :(得分:2)
ShowDeatils
从JFrame
延伸,而在其构造函数中,您正在创建另一个JFrame
,因此,每次创建新实例{{}}时,您都会创建两个框架{1}}
<强>更新强>
基本上,或者您需要做的是......
showDetails