Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: wait for ActionEvent

I want to make a method wait until an ActionEvent method has processed before continuing. Example:

public void actionPerformed(ActionEvent evt) {

    someBoolean = false;

}

the actionPerformed method is linked to a textField I have, and the method is triggered when you press Enter. What I want to do, is have a different method pause until the actionPerformed method happens. Example:

public void method() {

    System.out.println("stuff is happening");
    //pause here until actionPerformed happens
    System.out.println("You pressed enter!");

}

Is there a way to do this?

like image 636
Blackvein Avatar asked Sep 28 '26 20:09

Blackvein


1 Answers

CountDownLatch should do the trick. You want to create a latch waiting for 1 signal.

Inside the actionPerformed you want to call countDown() and inside "method" you just wanting to await().

-edit- I'm assuming that you've already got the right amount of Threads set up to handle the situation.

like image 95
pimaster Avatar answered Sep 30 '26 10:09

pimaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!