0

I am using Java Swing in Netbeans and MySQL. I am designing a very simple user login application. I have two jFrames. One is for the login page that asks user to enter their ID and Password. Once the user account is searched and verified in database, the other jFrame simply displays the user information, such as name, address, and email address that is associated with the account.

So I have 2 jFrame forms (login and profile) and one class that has all the information about the user (String name, String address, String email).

My question is how does the profile jFrame display what was entered in login jFrame? For example, I'd like to say "Hi, 'username'".

// profile jFrame constructor 
public profile() {
   Login login = new Login();
   JOptionPane.showMessageDialog(null, "Hi" + login.getName());  
   // Display any info associated with login.getName() in database
}

// inside login jFrame class
public String getUsername() {
    String user = jTextName.getText();
    return user;
}

First, login.getName() only displays "Frame0". And I think my design is not how usually it's done for such applications. Please help.

Mint.K
  • 849
  • 1
  • 11
  • 27
  • That's actually a broad question which could be answered successfully in a number of ways. One of the preferred solutions would involve a another "controller" class, which was responsible for managing the frames. It would display the "login" frame and wait for some kind of notification from the "login" frame that either the login has been successful or failed. The "login" frame would be required to return an instance of the "profile" object if login was successful. – MadProgrammer Feb 25 '18 at 21:47
  • 1
    When successful, the "controller" would then create an instance of the "profile" frame, passing it the "profile" object it got from the "login" frame – MadProgrammer Feb 25 '18 at 21:47
  • 1
    All of this takes in concepts like the "observer pattern" and "model-view-controller" paradigms. You may also like to have a look at [Passing Information to a Method or a Constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html) – MadProgrammer Feb 25 '18 at 21:49
  • Now, if you're up for some mind bending theory - you could have a look [at this example](https://stackoverflow.com/questions/26517856/java-and-gui-where-do-actionlisteners-belong-according-to-mvc-pattern/26518274#26518274) or [this example](https://stackoverflow.com/questions/27663306/open-a-jpanel-after-pressing-a-button-in-a-jframe/27663749#27663749) or even [this example](https://stackoverflow.com/questions/29571722/java-application-with-multiple-scenes/29639672#29639672) which all demonstrate the use of MVC and observer patterns based around a login example - yes, this gets asked a bit – MadProgrammer Feb 25 '18 at 21:51
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Feb 26 '18 at 08:39

0 Answers0