Am currently doing a project with a java GUI interrogating a database. My first GUI is a [U]Login[/U] display which when the user successfully logs in will move onto a [U]Menu[/U] display. My problem is that I cannot get from the [U]Login[/U] display to the [U]Menu[/U] display. These GUIs have been set up using JBuilder3.

I can see that I am successfully logging on in that the login display disappears but the next page wont appear.

The frames were set up using a JDesktopPane which supports the various JInernalFrames.

The desktop pane however was created by default with a menu bar which when you open the file option has new frame as an option. It is in fact necessary to use this facility to get my login display on the screen at the star.

Clarifying this issue would be pretty critical in moving on with this project.

Below is the code for the OK button on the [U]Login[/U] display with the ref to [U]mainMenu[/U] being the display I'm trying to get to.

Thanks in advance

 void buttonOK_actionPerformed(ActionEvent e) {
    Statement statement;
    ResultSet resultset;
    String accesslevel = (String) jComboBoxLevel.getSelectedItem();
    String uname, pword, unamedb, pworddb;
    if (accesslevel == "Librarian") {
      try {
        uname = jTextFieldUsername.getText();
        pword = jTextFieldPassword.getText();
        statement = connection.createStatement();
        resultset = statement.executeQuery("Select * From Librarian_Logon_Table");
        while (resultset.next()) {
          unamedb = resultset.getString(2);
          pworddb = resultset.getString(3);
          if (unamedb.equals(uname) && pworddb.equals(pword)) {
            try {
              this.setVisible(false);
              mainMenu m = new mainMenu();
              m.setVisible(true);
            }
            catch (Exception e1) {
              JOptionPane.showMessageDialog(null, "Problem 1", "Problem 1", JOptionPane.INFORMATION_MESSAGE);
            }
          }
        }
        jTextFieldUsername.setText("");
        jTextFieldPassword.setText("");
      }
      catch (Exception e1) {
        JOptionPane.showMessageDialog(null, "Problem 2", "Problem 2", JOptionPane.INFORMATION_MESSAGE);
      }
    }
    else {
      JOptionPane.showMessageDialog(null, "Choose the correct choice from combo box", null, JOptionPane.INFORMATION_MESSAGE);
      jTextFieldUsername.setText("");
      jTextFieldPassword.setText("");
    }
  }
}

You probably need to add the menu frame to the desktop pane such as in this code fragment

protected void createFrame() {
    MyInternalFrame frame = new MyInternalFrame();
    frame.setVisible(true);
    desktop.add(frame);
    try {
        frame.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}
}

Is there a particular reason you need to use the JDesktopPane and internal frames, instead of standalone JFrames?

Thanks for that will try it out in the next few minutes.
By implication of your comment I would be better off going back and restarting and creating each of the GUI displays in its own individual frame.
Would my code be along the correct lines to get the mainMenu up on the screen if I were to start again and give each display its own display.
I presume that if i were to do this that the LogOn (being the first display) would be the only one to have a main()
Thanks for the help

Thanks for that will try it out in the next few minutes.
By implication of your comment I would be better off going back and restarting and creating each of the GUI displays in its own individual frame.
Would my code be along the correct lines to get the mainMenu up on the screen if I were to start again and give each display its own display.

It just depends on how you wish your app to behave. If you need to maintain several documents and panels open at the same time, but need them constrained in a single parent frame, then stick with the JDesktopPane. On the other hand, if you are primarily working from one frame at a time or wish to have the ability to maximize multiple frames on different monitors, you are better off with regular JFrames. On my current project, most users have 3 monitors and prefer individual components that they can organize as they please without the limit of a single desktop container frame. So it's a matter of how you want to present the components to the user. If it's a single screen app for the most part, you certainly won't need a desktop pane.

I presume that if i were to do this that the LogOn (being the first display) would be the only one to have a main()
Thanks for the help

Yes, the login would be the entry point with a main method. On successful login you would proceed much like your current code. I would recommend also calling the dispose() method on the login frame after you are done with it.

This tutorial has info on using Internal Frames and how they vary from regular Frames:
http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.