Link/Show Form when clicking a Button in Java

Language

This is a continuation of Login Tutorial and Connecting to MS Access database using JCreator see here With this, I am showing you some twist that after a correct login in the program it will show another form in Java. 1. First create a java program with a filename of MainMenu.java. 2. Import the following libraries.
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.io.*;
3. Initialize the following variables below.
  1. JDesktopPane desktop = new JDesktopPane();;
  2. String TITLE = "This is another form";
  3. JMenuBar menubar = new JMenuBar();
  4. JPanel panel_Bottom = new JPanel();
  5. JPanel panel_Top = new JPanel();
4. Create a constructor named MainMenu.
  1. public MainMenu() {
  2. super("This is another form");
  3. desktop.setBackground(Color.black);
  4. panel_Top.setLayout(new BorderLayout());
  5. panel_Top.setPreferredSize(new Dimension(10,150));
  6.  
  7. getContentPane().add(panel_Top,BorderLayout.PAGE_START);
  8. getContentPane().add(desktop,BorderLayout.CENTER);
  9. getContentPane().add(panel_Bottom,BorderLayout.PAGE_END);
  10.  
  11.  
  12. };
5. Create a method setMain. Instead of using the Main args, we will just use this method and will call from the Login.java.
  1. public void setMain(){
  2. MainMenu p1= new MainMenu();
  3. p1.setSize(1275,950);
  4. p1.setLocation(2,2);
  5. p1.setVisible(true);
  6. p1.setResizable(false);
  7. }
6. In your Login.java in this this previous link see here. Add the code below.
  1. if((loginname.equalsIgnoreCase(txtuser.getText()))&&(loginpass.equalsIgnoreCase(txtpass.getText())))
  2. {
  3.  
  4.  
  5. MainMenu menu = new MainMenu();
  6. menu.setMain();
  7. dialogmessage = "Welcome - "+loginname;
  8. dialogtype = JOptionPane.INFORMATION_MESSAGE;
  9. JOptionPane.showMessageDialog((Component)null, dialogmessage, dialogs, dialogtype);
  10. txtuser.setText("");
  11. txtpass.setText("");
  12. dispose();
  13.  
  14. }
MainMenu menu = new MainMenu() and menu.setMain() was called when the button with a correct login is clicked and it will show the MainForm. For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Add new comment