Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6377535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:53:11+00:00 2026-05-25T01:53:11+00:00

I try build the 2 Class: LoginScreen Class and MainScreen Class When I run

  • 0

I try build the 2 Class: LoginScreen Class and MainScreen Class

When I run program it will show the login screen first then I use username and password to login the Mainscreen are pop-up but the login screen doesn’t disappear.I am not sure how to handle it correctly.

Because the method I use is

public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();

   if (OK.equals(cmd)) { //Process the password.
       char[] input = passwordField.getPassword();
       if (isPasswordCorrect(input)) {
           javax.swing.SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                  JFrameExample.main(null);
               }
           });
       } else {
           JOptionPane.showMessageDialog(controllingFrame,
               "Invalid password. Try again.",
               "Error Message",
               JOptionPane.ERROR_MESSAGE);
       }

       //Zero out the possible password, for security.
       Arrays.fill(input, '0');

       passwordField.selectAll();
       resetFocus();
   } else { //The user has asked for help.
       JOptionPane.showMessageDialog(controllingFrame,
           "You can get the password by searching this example's\n"
         + "source code for the string \"correctPassword\".\n"
         + "Or look at the section How to Use Password Fields in\n"
         + "the components section of The Java Tutorial.");
   }

}

I know this is the stupid code and wrong way to implement it but can you guide me to make the appropriate one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:53:12+00:00Added an answer on May 25, 2026 at 1:53 am

    I guess this method is a method of your first screen, which must be a JDialog or a JFrame. Just call setVisible(false) to hide the frame (you may also call dispose() if the dialog won’t be used anymore).

    Also, you shouldn’t call the main method on JFrameExample. A main method is normally used to start a new application. Just do what the main method does from your action listener (probably new JFrameExample().setVisible(true)).

    Finally, an event listener is always invoked in the event dispatch thread (EDT), so there is no point in using SwingUtilities.invokeLater from an event listener.

    To recap, here’s how the code should look like:

    if (isPasswordCorrect(input)) {
        setVisible(false); // or dispose();
        JFrame mainFrame = new JFrameExample();
        mainFrame.setVisible(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build this class (to use in ASP.NET site) that will Crop
I'm try to build a static property on a static class that will basically
I am about to try and automate a daily build, which will involve database
I try to build some application using hibernate for persistence (my first one). The
when i try to build and run my app, it crashes and i got
I try to build a gui (Swing) for a simple java application. The application
i try to build a app that is in landsscape mode all the time.
When I try to build my project I get the following message in the
When I try to build my projects in Visual Studio 2008, web sites won't
When I try to build a project in Visual Studio 2005 that has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.