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 7279101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:58:45+00:00 2026-05-28T22:58:45+00:00

What I need to do is to prompt the user with a username and

  • 0

What I need to do is to prompt the user with a username and password (authentication is done locally) and if it checks out, the user would then be able to access the main program body.

public static void main(String[] args){

  //String input = JOptionPane.showInputDialog("Enter password to continue: ");
  //input2 = Integer.parseInt(input);


  // followed by the creation of the main frame
  new Cashier3();
  Cashier3 frame = new Cashier3();
  frame.setTitle("CASHIER 2");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);

is there any quick way to go about doing this?

  • 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-28T22:58:47+00:00Added an answer on May 28, 2026 at 10:58 pm

    You can simply add a static block to your program where you will do your authentication, this static block is always executed before the main method. If the user is not valid go with

    System.exit(0);
    

    to exit the program. Else the program will start execution as usual.

    Here is one sample program to give you some idea :

    import java.awt.Color;
    import javax.swing.*;
    
    public class Validation extends JFrame
    {
        private static Validation valid = new Validation();
        static
        {
            String choice = JOptionPane.showInputDialog(valid, "Enter Password", "Password", JOptionPane.PLAIN_MESSAGE);
            if ((choice == null) || ((choice != null) && !(choice.equals("password"))))
                System.exit(0);
        }
    
        private static void createAndDisplayGUI()
        {
            valid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            valid.setLocationRelativeTo(null);
    
            valid.getContentPane().setBackground(Color.YELLOW);
    
            valid.setSize(200, 200);
            valid.setVisible(true);
        }
        public static void main(String... args)
        {
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    createAndDisplayGUI();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display a prompt to get a user's username and password. I
I need to prompt for a username and password from a batch script subroutine
I need to prompt user to insert second Disc to continue installation. I am
I have encrypted documents. After unarchiving each document, I need to prompt the user
I need to prompt a user to save their work when they leave a
I need to prompt to user a msg that tells him to write a
So what I need is to make the installation wizard that will prompt user
I need to get a Username and Password...I'm doing Password Recovery in my Application
I need to trigger an executable file(built using .net) using the command prompt. For
I need one of my .exe to always run as administrator without UAC prompt.

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.