I was wondering if there was a method for JButtons that is, and I'm just guessing here, essentially a boolean that would be assigned a true
or false
value depending on whether or not a button is clicked. I understand that there are actionListeners and keyListeners and MouseListeners and a plethora of listeners, but I am searching for a method that would do something like this:
public boolean ButtonClickDetector (just pretend it's real)
{
if(JButton.isClicked())
{
return true;
}
else
{
return false;
}
I need this so that I can increase an integer only when a button is clicked. I have thought about just putting integer++;
into the actionPerformed
but I feel if I had a boolean, the code would function better, be less prone to error, and perhaps a bit more efficient. Please note, I am a high schooler and do not have oodles and oodles of coding experience so PLEASE dumb down your answers. When answering PLEASE PROVIDE AN EXAMPLE AND EXPLANTION OF WHAT YOU ARE SHOWING ME. Accompanying an example and explantion with documentation would be wonderful. Thanks.