Application.DoEvents () & # 8594; Equivalent function in java?

I know that using threads is more efficient than using C # DoEvents (), but I'm still wondering if there is an equivalent function in java. I was looking for her, but I did not find anything.

+5
source share
3 answers

You can use Thread.yield(), which is a Java partner, to voluntarily give up processor control.

+2
source

You can use EventQueue.invokeLater()to add Runnableafter all pending events. This is a result similar to C # DoEvents(), which precedes the code entered inside the method Runnable.run().

. Java EventQueue.

, , -, , :

@Override 
public void windowClosing(WindowEvent e){
    // Clear the focus to allow last changes to be noted. 
    KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
    // We want to let other events (e.g. lost focus) run before we start closing.
    EventQueue.invokeLater( new Runnable() {
        @Override public void run() {
            // Do actual closing...
        }
    });
}
+1

It is called an event loop. This article shows how events are handled in user interface components in Java.

0
source

All Articles