Get assigning var from mouse clicked

53 Views Asked by At

So this is how it works, I add a mouse clicked method and when it is clicked then alreadyClicked = true; then I check var alreadyClicked which should be true with a conditional in main or constructor if (alreadyClicked == true){ System.out.println("True");}.

And somehow the output doesn't print, it's like I can't get the variable assignment from my mouseClicked method. Or maybe it's just me who's wrong

for note: i already declare Boolean alreadyClicked in global

  public void mouseClicked(MouseEvent e) {
    alreadyClicked = true;}
public static void main(String[] args) {
    MyClass myClass = new MyClass();
    if (myClass.alreadyClicked){
        System.out.println("true");
    }
 }
0

There are 0 best solutions below