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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:07:33+00:00 2026-05-23T21:07:33+00:00

something seems to be going wrong with the block of code that tries to

  • 0

something seems to be going wrong with the block of code that tries to set the String variable, as no matter what I do when I run the program, the Dialog Box always shows otto. Does anyone know what I’m doing wrong here?

Thanks,
Ravin

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class SmallTingz extends JFrame {
    private JLabel item1;
    private JTextField tf;
    private JTextField tf2;
    private JTextField tf3;
    private JPasswordField pf;

    public SmallTingz() {
        super("The Title");
        setLayout(new FlowLayout());
        JTextField tf = new JTextField("Cool Beans");
        JTextField tf2 = new JTextField("UnCool Beans");
        JTextField tf3 = new JTextField("Hot Beans");
        JPasswordField pf = new JPasswordField("password");

        add(tf);
        add(tf2);
        add(tf3);
        add(pf);

        thehandler handler = new thehandler();
        tf.addActionListener(handler);
        tf2.addActionListener(handler);
        tf3.addActionListener(handler);
        pf.addActionListener(handler);
    }

    private class thehandler implements ActionListener {

        public void actionPerformed(ActionEvent event) {
            String string;          
            if (event.getSource() == tf)
                string=String.format("field1: %s", event.getActionCommand());
            else if (event.getSource() == tf2)
                string=String.format("field2: %s", event.getActionCommand());
            else if (event.getSource() == tf3)
                string=String.format("field3: %s", event.getActionCommand());
            else if (event.getSource() == pf)
                string=String.format("passfield: %s", event.getActionCommand());
            else
                string="otto";

            JOptionPane.showMessageDialog(null, string);        
        }
    }
}
  • 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-23T21:07:33+00:00Added an answer on May 23, 2026 at 9:07 pm

    In your SmallTingz() constructor, remove all variable declarations. Your declarations is hiding the member variables.

    Change

    JTextField tf = new JTextField("Cool Beans");
    JTextField tf2 = new JTextField("UnCool Beans");
    JTextField tf3 = new JTextField("Hot Beans");
    JPasswordField pf = new JPasswordField("password");
    

    to

    tf = new JTextField("Cool Beans");
    tf2 = new JTextField("UnCool Beans");
    tf3 = new JTextField("Hot Beans");
    pf = new JPasswordField("password");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to write something that seems like it should be easy enough,
I am having a heck of time with something that seems rather straightforward but
I was doing some performance metrics and I ran into something that seems quite
Whichever way I do it, it seems something goes wrong when using the conditional
Something very basic seems to be escaping me. Dim foo As New Dictionary(Of String,
Is there some easy way to pad Strings in Java? Seems like something that
I'm still working on a particular RDF file, but seems that something is not
It seems like there should be something shorter than this: private string LoadFromFile(string path)
Can't seem to figure out where Im going wrong here: private static String generateHashFromFile(String
What could be going wrong here? The problem seems to be with the regex

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.