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

  • Home
  • SEARCH
  • 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 9011047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:37:26+00:00 2026-06-16T02:37:26+00:00

I am coding a Java game that uses mouse actions. I have a point

  • 0

I am coding a Java game that uses mouse actions. I have a point msc in my main class – it gets changed whenever I press the mouse and gets set to (0, 0) whenever I release the mouse. For the buttons, they check if msc is inside their rectangle, and if so, call click.

One of the buttons is supposed to toggle a boolean; when I click on it though, it switches true and false very fast because msc gets updated every time paintComponent is called.

Here is the code for the button click method:

if (button.contains(Screen.msc)) {
    beenClicked = true;
    this.width = this.width - 2;
    this.height = this.height - 2;
    this.x = this.x + 1;
    this.y = this.y + 1;
    g.setColor(currColor);
    textColor = Color.YELLOW;
}

but that is not where the problem is I think. Here is the code that changes msc:

public void mouseReleased(MouseEvent e) {
    Screen.msc = new Point(0, 0);
}

public void mousePressed(MouseEvent e) {
    Screen.msc = new Point((e.getX()) - ((Frame.size.width - Screen.myWidth) / 2), e.getY() - ((Frame.size.height - (Screen.myHeight)) - (Frame.size.width - Screen.myWidth) / 2));
}

and the code for what happens when the specific toggle button is clicked:

if (toggleToolTips.clicked()) {
    if (Screen.canDrawTooltip) {
        Screen.canDrawTooltip = false;
    } else if(!Screen.canDrawTooltip){
        Screen.canDrawTooltip = true;
    }
}   

The problem is every time I go and click the button, the boolean switches back and forth real fast. When I hold it, it just rapidly and continually switches. I would like to make it so that I click once and it switches once.

  • 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-06-16T02:37:27+00:00Added an answer on June 16, 2026 at 2:37 am

    Your setting the boolean beenClicked but are not checking it anywhere. I would suggest trying

    if (!beenClicked && toggleToolTips.clicked()) 
    {   
        Screen.canDrawTooltip = !Screen.canDrawTooltip);
    }
    

    And setting beenClicked back to false somewhere such as mouseReleased.

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

Sidebar

Related Questions

I am coding a text based Java game, I have ran into a few
I have following UML class diagram and java coding for each, please tell me
I've been coding in Java for the past year, and i think I have
I'm doing some JAVA coding at home and at work. At home i have
I’m new to web development but have coding experience (Java) and I’m trying to
When I am coding Java in Eclipse I like the auto-completion feature. With that
i am relatively experienced in Java coding but am new to C++. I have
I have two arrays for a chess variant I am coding in java...I have
To those unfamiliar, javabat is a website that hosts dozens of small java coding
We found out that run length is much better than huffman coding (JAVA) considering

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.