public class MainFrame {
private JFrame mainframe;
private JLabel JL_username;
private JLabel JL_password;
private JLabel JL2_password;
private JTextField JTF_username;
private JPasswordField JPF_password;
private JPasswordField JPF2_password;
private JButton button1;
public MainFrame(){
setMainFrame();
}
public void setMainFrame(){
mainframe = new JFrame("注册窗口");
mainframe.setBounds(200,100,250,250);
mainframe.setVisible(true);
mainframe.setResizable(true);
setMainFramezujian();
}
public void setMainFramezujian(){
JL_username = new JLabel("用户名");
JTF_username = new JTextField(13);
JL_password = new JLabel("密码");
JPF_password = new JPasswordField(13);
JL2_password = new JLabel("密码");
JPF2_password = new JPasswordField(13);
button1 = new JButton("注册");
JPanel p1 = new JPanel();
FlowLayout FL = new FlowLayout(FlowLayout.RIGHT,15,15);
p1.setLayout(FL);
p1.add(JL_username);
p1.add(JTF_username);
p1.add(JL_password);
p1.add(JPF_password);
p1.add(JL2_password);
p1.add(JPF2_password);
mainframe.add(p1);
JPanel p2 = new JPanel();
FlowLayout FL2 = new FlowLayout(FlowLayout.CENTER,15,12);
p2.setLayout(FL2);
p2.add(button1);
mainframe.add(p1);
mainframe.add(Box.createVerticalStrut(20),BorderLayout.NORTH);
mainframe.add(Box.createHorizontalStrut(10),BorderLayout.EAST);
mainframe.add(p2,BorderLayout.SOUTH);
}
public static void main(String[] args) {
MainFrame login = new MainFrame();
}
}运行的结果是一个空的框框,但是鼠标点击一下边框,里面的内容才能正常显示,是怎么回事,代码的问题吗