简体   繁体   English

将JFrame或JDialog添加到java netbeans应用程序

[英]Add JFrame or JDialog to java netbeans application

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. 我正在netbeans 7中开发一个java GUI应用程序,我有一个处理文件的窗口(SingleFrameApplication),我需要在这个主框架之前启动登录屏幕,我不明白如何添加新框架,或者如何延迟主帧直到新帧中的登录正确。

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();
        }

    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM