Mouse Input Per Second on Button Problems

I have a java game that I get mouse actions in. I have a point msc in my main class, msc gets changed whenever I press the mouse and gets set to 0, 0 whenever I release he mouse. For my buttons that I coded, they check if the msc is inside their rectangle and if so call click. I have a button that toggles a Boolean and as a result of that when I click on it it switches true and false very fast because the msc gets updated every time paintComponent is called. I would like to know how i could click it and have it switch once, then click it and switch again and so forth.

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;
        }
    }   

Haven’t read your post yet, but use code tags.

ok, im new to this site so I dont really know how

Highlight your code and press the button with the # symbol (it’s in the row of buttons directly above the emoticons)

alright I have done thatt

If you want a on/off switch GUI component the easy way would be to use a JRadioButton or JCheckBox.
Or if you want to stick something more like a JButton use a JToggleButton.

well I am hardcoding all of the gui elements to the game myself to get as much control as possible and it is also a good learning experience for me.

in the spot where you change the boolean for visible you could make the code something like this:


if(msc.x==0&msc.y==0&isVisible==true)
{
isVisible=false;
}else if(isVisible==false)
{
isVisible= true;
}

Is that what you’re looking for?

YES! Thank you very much I felt like such an idiot after seeing this! This solved it!