• We just launched and are currently in beta. Join us as we build and grow the community.

Link/Show Form when clicking a Button in Java

hmimedmikrob3

Mecha Builder
H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
105
Likes
118
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
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. getContentPane(

    )

    .add

    (

    panel_Top,BorderLayout

    .PAGE_START

    )

    ;
  7. getContentPane(

    )

    .add

    (

    desktop,BorderLayout

    .CENTER

    )

    ;
  8. getContentPane(

    )

    .add

    (

    panel_Bottom,BorderLayout

    .PAGE_END

    )

    ;


  9. }

    ;

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. MainMenu menu =

    new

    MainMenu(

    )

    ;
  4. menu.setMain

    (

    )

    ;
  5. dialogmessage =

    "Welcome - "

    +

    loginname;
  6. dialogtype =

    JOptionPane

    .INFORMATION_MESSAGE

    ;
  7. JOptionPane

    .showMessageDialog

    (

    (

    Component

    )

    null

    , dialogmessage, dialogs, dialogtype)

    ;
  8. txtuser.setText

    (

    ""

    )

    ;
  9. txtpass.setText

    (

    ""

    )

    ;
  10. dispose(

    )

    ;

  11. }

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.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

440,010

316,559

316,568

Top