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