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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:12:06+00:00 2026-05-26T16:12:06+00:00

My problem seems to be quite simple, but I’ve been stuck on it for

  • 0

My problem seems to be quite simple, but I’ve been stuck on it for months; and now that it’s an assignment requirement, due two days from now, I have to give up and ask for help.

Basically, I have an int variable (called Score here), and a button that change the value of this variable; this works. But I also have a display of the present value of Score, and I want it to change to represent the value. However, it stays at 0, and doesn’t change at all.

I’ve made a piece of code as simple as possible (the actual project has around 15 files) which includes this problem: a button that displays the value of Score, and increments it. If someone could give me a solution on how to have the displayed value be the same as the value of the variable, that would be great 🙂

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class Main extends JFrame {
public static void main (String [] args) {
new Main();
}

public Main () {
setLocation (100, 100);
setSize (200, 200);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
content.add (new CrisButton ());
setVisible (true);
}

public class CrisButton extends JButton implements ActionListener{

    public int Score;
    CrisButton(){
        setText(""+Score);
        addActionListener(this);
    }

    public void actionPerformed(ActionEvent e){
        System.out.println("Score="+Score);
        Score=Score+2;
        this.repaint();
    }
}

}
  • 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-26T16:12:07+00:00Added an answer on May 26, 2026 at 4:12 pm

    You must use this.setText(“” + Score);

    Score does not act as a pointer, so the value will never change.
    You have to pass in a completely new string each time.

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

Sidebar

Related Questions

My problem seems to be quite simple, but it's not working the intuitive way.
My problem seems simple, but for some reason, I can't quite seem to fix
I have a (hopefully quite simple) Javascript problem. I've search but found nothing that
Im quite sure there is a very simple fix to my problem, but i
This is probably quite a simple problem, but it's causing me to scratch my
On the face of it, this seems a very simple problem but for some
I have a strange problem that I can't seem to solve. I've quite a
My problem seems to be this: heap data allocated by one thread (that later
I have a problem that seems like its a result of a deadlock-situation. Whe
I have a problem that seems so senseless that I'm sure I'm missing something

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.