Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 完成某项任务后关闭内部框架_Java_Swing_User Interface_Jinternalframe - Fatal编程技术网

Java 完成某项任务后关闭内部框架

Java 完成某项任务后关闭内部框架,java,swing,user-interface,jinternalframe,Java,Swing,User Interface,Jinternalframe,这是我的代码: public class DesktopFrame extends JFrame{ private JDesktopPane theDesktop; private JInternalFrame login; private JMenuBar bar; private JMenu fileMenu; private JMenuItem newLoginFrame; private LoginPanel panel; //

这是我的代码:

public class DesktopFrame extends JFrame{
    private JDesktopPane theDesktop;
    private JInternalFrame login;
    private JMenuBar bar;
    private JMenu fileMenu;
    private JMenuItem newLoginFrame;
    private LoginPanel panel;

    // set up GUI
    public DesktopFrame(){
        super( "Application" );
        bar = new JMenuBar(); // create menu bar
        bar.setBackground(new Color(255,215,0));
        fileMenu = new JMenu( "File" ); // create Add menu
        fileMenu.setBackground(new Color(255,215,0));
        newLoginFrame = new JMenuItem( "Login" );
        newLoginFrame.setBackground(new Color(255,215,0));
        fileMenu.add( newLoginFrame ); // add new frame item to Add menu
        bar.add(fileMenu); // add Add menu to menu bar
        setJMenuBar(bar); // set menu bar for this application
        theDesktop = new JDesktopPane(); // create desktop pane
        theDesktop.setBackground(Color.BLUE);
        add(theDesktop); // add desktop pane to frame
        // set up listener for newLoginFrame menu item
        newLoginFrame.addActionListener(new ActionListener(){ // anonymous inner class
            // display new internal window
            public void actionPerformed( ActionEvent event ){
                login = new JInternalFrame("Member Login", false, false, false, false);
                panel = new LoginPanel();
                login.add( panel, BorderLayout.CENTER ); // add panel
                login.setSize(375,300);
                login.setLocation(20,20);
                theDesktop.add( login ); // attach internal frame
                login.setVisible( true ); // show internal frame
            } // end method actionPerformed
        } // end anonymous inner class); // end call to addActionListener
    } // end DesktopFrame constructor

    public void getValid(){
        if(panel.getValid() == true){
            try{
                login.setClosed(true);
            }
            catch(PropertyVetoException p){     
            }
        }
    }
} // end class DesktopFrame

在本文档中,还有另一个类“LoginPanel”,它处理所有登录框架。如果用户名/密码有效,它将创建一个布尔变量“valid”,该变量为true。我用“panel.getValid()”调用了它。如您所见,其目的是在“valid”为true时退出登录框架。这可能吗?人们推荐什么?现在,使用“setClosed”,它将退出整个框架,而不仅仅是内部的“Login”框架。我不知道为什么

我认为更好的办法是为登录创建JDialog(对于JDialog docu,请参见),使用它的方式与使用内部框架的方式类似。成功登录后,在JDialog上调用dispose()


应提供帮助。

1)不要延伸框架或其他顶级容器。而是创建并使用一个实例。2) 对代码块使用一致的逻辑缩进。代码的缩进旨在帮助人们理解程序流程。3) 为了更快地获得更好的帮助,请发布一条@user2518777。如果这是您预先提供的解决方案,您可以接受答案+1@用户2518777还可以查看使用
JDialog
进行输入验证的答案。