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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:39:58+00:00 2026-05-27T11:39:58+00:00

I have an annoying message box that pops up when I dont want it.

  • 0

I have an annoying message box that pops up when I dont want it.
the problem occurs after a user logs on and the hidden button is visible, but when it is clicked it show the “correct” message again? Ive also tried putting it on top of the first statement and bottom.
EDIT:The annoying message is the message that comes up after a successful login, and no I dont need to spell check,

class MyWindowListener extends WindowAdapter {

    public void windowClosing(WindowEvent e) {
        System.out.println("Closing window!");
        System.exit(0);

    }
}
class LoginForm extends JFrame implements ActionListener {

    private final String username = "user";
    private final String password = "pass";
    JFrame frame;
    JPanel jPanel;
    JLabel userLabel;
    final JTextField userText;
    JLabel passLabel;
    final JPasswordField passText;
    JButton loginBtn;
    JButton shopBtn;
    JLabel welcome;

    {

        frame = new JFrame();
        jPanel = new JPanel();
        userLabel = new JLabel("Login : ");
        userText = new JTextField(10); 
        passLabel = new JLabel("Password : ");
        passText = new JPasswordField(10);
        loginBtn = new JButton("Login");
        shopBtn = new JButton("Go to Shop");
        welcome = new JLabel("Welcome to ECSE501 Computers");
        setTitle("Login Page");
        loginBtn.addActionListener(this);
        shopBtn.addActionListener(this);


        Container c1 = new Container();
        c1.setLayout(new GridLayout (3,2));
        c1.add(userLabel);
        c1.add(userText);
        c1.add(passLabel);
        c1.add(passText);
        c1.add(loginBtn);

        Container c2 = new Container();
        c2.setLayout(new BoxLayout(c2, BoxLayout.Y_AXIS));
        c2.add(welcome);
        c2.add(shopBtn);
        welcome.setVisible(false);
        shopBtn.setVisible(false);

        add(jPanel);
        jPanel.add(c1);
        jPanel.add(c2);

    }

    public void actionPerformed(ActionEvent e) {

        String userInput = userText.getText();
        char[] pass = passText.getPassword();
        String p = new String(pass);



        if (userInput.equals(username) && p.equals(password)) {
            jPanel.setVisible(true);
            welcome.setVisible(true);
            jPanel.setBackground(Color.green);
            JOptionPane.showMessageDialog(null, "Correct");
            shopBtn.setVisible(true);
            JButton hiddenBtn = (JButton) e.getSource();
        if ( hiddenBtn == shopBtn)  
         {
            SelectionForm selection = new SelectionForm();
            selection.select();
        }
        }
        else {   
            jPanel.setBackground(Color.red);
            JOptionPane.showMessageDialog(null, "Wrong Login Details");

        }


    }
}
public class LoginTester {

    public static void main(String[] args) { 

        // register an event handler for frame events
        LoginForm frame = new LoginForm();
        frame.addWindowListener(new MyWindowListener());
        frame.setSize(300, 200);
        frame.setVisible(true);

        //frame.pack();
        }
    }
  • 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-27T11:39:58+00:00Added an answer on May 27, 2026 at 11:39 am

    You put this all in your actionPerformed method. That is called whenever any action is performed, a button is clicked, a text field is edited, etc…

    If you don’t want this to run when you click the button, check for the source of the event, using getSource(), and if the source is the button, then don’t run the code. Your method would look like this:

        public void actionPerformed(ActionEvent e) {
            String userInput = userText.getText();
            char[] pass = passText.getPassword();
            String p = new String(pass);
    
            if(e.getSource().equals(loginBtn)) {
    
                if (userInput.equals(username) && p.equals(password)) {
    
                    jPanel.setVisible(true);
                    welcome.setVisible(true);
                    jPanel.setBackground(Color.green);
                    JOptionPane.showMessageDialog(null, "Correct");
                    shopBtn.setVisible(true);
                    JButton hiddenBtn = (JButton) e.getSource();
                }
    
                else {
                    jPanel.setBackground(Color.red);
                    JOptionPane.showMessageDialog(null, "Wrong Login Details");
                }
            }
    
            else if (e.getSource().equals(shopBtn)) {
    
                SelectionForm selection = new SelectionForm();
                selection.select();
    
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a annoying problem .. I want my first 4 items in a
Basically we have the illusion of an notification message box that exists as .Visible
I have this annoying problem, that Im pretty sure happens to all of you
I have an annoying problem with the debug mode of Visual C++ 2005. My
i have this annoying problem with my site where, when you click on a
XML is cool in flex, but I have an annoying problem to solve, caused
Hey I have a really annoying IE7 bug that I am trying to work
I've recently begun learning C# but have encountered an annoying problem. Every variable I
I have a very annoying problem and I'm trying to find the simplest solution
In my Swing application I have the problem that when creating a new instance

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.