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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:07:54+00:00 2026-05-18T10:07:54+00:00

I have a value called ‘AmountWrongGuessed’ that gives the amount of wrong guesses the

  • 0

I have a value called ‘AmountWrongGuessed’ that gives the amount of wrong guesses the users puts while guessing a word.
Each times the word is not found in the arraylist the AmountWrongGuessed goes ++. (tested this wih a println and it works properly)

Now the problem is each time the AmountWrongGuessed goes 1 up it should display a ImageIcon.
But insteed it displays the last image icon all the time, and skips the other icons.

I use no layout mananger (its set to null, if this makes any difference in the total picture setLayout = null)

Also while initialising this game the amountwrongguessed is default 0, yet it does not display the first imageicon either. (i used different labels before to add each icon on the same position but then i had the problem only the first image displayed and nothing changed).

public HrView(Hrgame hg) {
    this.hg = hg;

    CreateComponents();
    SetLayoutComponents();
    UpdateComponents();
    AddListeners();
}

Creation of the images:

 private void CreateComponents() {

    hang0 = new ImageIcon("hang0.gif");
    lblHang = new JLabel(hang0);
    lblHang.setLocation(60, -10);
    lblHang.setSize(200, 200);       

    hang1 = new ImageIcon("hang1.gif");
    lblHang = new JLabel(hang1);
    lblHang.setLocation(60, -10);
    lblHang.setSize(200, 200);

    hang2 = new ImageIcon("hang2.gif");
    lblHang = new JLabel(hang2);
    lblHang.setLocation(60, -10);
    lblHang.setSize(200, 200);
}

  private void AddListeners()
{
    btnCheck.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent e)
        {

            hg.Input(tfToGuessInput.getText().toLowerCase());
            Pictures();
            lblHang.updateUI();

        }
    });
}


private void Pictures()
{
    //works, does increment
    System.out.println(hg.getAmountWrongGuessed());

    if (hg.getAmountWrongGuessed() == 0) {
        add(lblHang);
    }
    if (hg.getAmountWrongGuessed() == 1) {
        add(lblHang);
    }
    if (hg.getAmountWrongGuessed() == 2) {
        add(lblHang);
    }
}
  • 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-18T10:07:55+00:00Added an answer on May 18, 2026 at 10:07 am

    After CreateComponents() your attribute lblHang references the label you created last (the one containing image hang2.) In order to use the 3 labels later on, you need to have 3 label attibutes which you can then use in Pictures().

    Btw, in Java the naming convention is that method names start with a lowercase character.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class, called DateField , that has a string Value property. If
I would just like your feedback on something. Basically I have a value called
I have a class with a Property called 'Value' which is of type Object.
I have a value in my MS SQL table column called XDATA like this:
I have a column called menu_order which has no default value. When I select
I Have a database called 'lms' with two tables loan and value, table loan
I have a PowerShell module called Test.psm1. I want to set a value on
In SQL I have a column called answer, and the value can either be
I have a value from a row in MySQL called ($)lesson_title... I want this
I have a class called Cell with two properties. One is called Value of

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.