我已经创建了一个登录页面,并希望仅在成功登录后才将其链接到另一个Jframe
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField1.getText().length()==0)
JOptionPane.showMessageDialog(null,"insert username");
else if(jPasswordField1.getPassword().length==0)
JOptionPane.showMessageDialog(null,"insert password");
else{
String user = jTextField1.getText();
char[] pass = jPasswordField1.getPassword();
String pwd = String.copyValueOf(pass);
if(validate_login(user,pwd))
JOptionPane.showMessageDialog(null,"Correct User");
else
JOptionPane.showMessageDialog(null, "Incorrect User or Password!");
}
}
我希望有一行代码将我带到新的JFrame
答案 0 :(得分:0)
好吧,只需创建一个JFrame
对象并设置其基本属性:
JFrame frame = new JFrame("your title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create components and put them in the frame.
frame.getContentPane().add(/* ... */);
//Size the frame.
frame.pack();
//Show
frame.setVisible(true);
现在由您决定如何处理原始窗口。如果要关闭它:
//suppose "origFrame" is your original JFframe
origFrame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));