-1

So this is my code:

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

In this document, there is also another class "LoginPanel" which handles all of the login frame. If the username/password work, it creates a boolean variable "valid" that is true. I have called it with "panel.getValid()". As you can see the purpose is to exit the login frame when "valid" is true. Is this possible? What do people recommend? Right now, with the "setClosed" it is exiting the entire frame, not just the inner "Login" frame. I don't know why

Andrew_CS
  • 2,542
  • 1
  • 18
  • 38
  • 2
    1) Don't extend frame or other top level containers. Instead create & use an instance of one. 2) Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. 3) For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Jun 27 '13 at 18:50

1 Answers1

1

I think better idea is to create JDialog for login (for JDialog docu see this link), work with it in similar way as you do with internal frame. After successful login call dispose() on JDialog.

This question and answers should be helpfull.

Community
  • 1
  • 1
1ac0
  • 2,875
  • 3
  • 33
  • 47
  • @user2518777 if it's your prefferred solution you can accept answer – 1ac0 Jun 27 '13 at 19:21
  • +1 ... @user2518777 Also see [this](http://stackoverflow.com/questions/13055107/joptionpane-check-user-input-and-prevent-from-closing-until-conditions-are-met/13055405#13055405) answer which uses a `JDialog` for input validation. – David Kroukamp Jun 27 '13 at 21:13