I'm developing a java GUI application in netbeans 7, I have a window that process files (SingleFrameApplication), and I need to launch a login screen before this main frame, I don't understand how to add the new frame, or how to delay the main frame until the login in the new frame is correct.
Thanks in advance.
The way I solved a similar problem was attaching a window listener to the main frame, that shows a modal confirm dialog.
Then if the dialog is confirmed but the login is wrong you can redisplay it. If it is canceled you can close the application.
JPanel loginPanel = new LoginPanel();
this.getFrame().addWindowListener(new WindowAdapter() {
public void showLoginDialog()
{
int result = JOptionPane.showConfirmDialog(
mainView.getFrame(),
loginPanel, "Login... ",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE,
null);
if (result == JOptionPane.OK_OPTION)
{
if(!loginPanel.checkLogin())
{
showLoginDialog();
}
}
else
{
System.exit(0); // replace with your more graceful shutdown code
}
}
@Override
public void windowOpened(WindowEvent e)
{
showLoginDialog();
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.