代码之家  ›  专栏  ›  技术社区  ›  oopbase Jayachandran Murugesh

在Java中应用dodoScript()->等效函数?

  •  5
  • oopbase Jayachandran Murugesh  · 技术社区  · 15 年前

    我知道使用线程比使用C.*doEvsServer()更有效,但我仍然想知道Java中是否有一个等价的函数。我在谷歌上搜索,但找不到任何东西。

    3 回复  |  直到 12 年前
        1
  •  2
  •   user1704124    12 年前

    你可以使用 Thread.yield() 这是Java对应自动放弃处理器的控制。

        2
  •  1
  •   amotzg    12 年前

    你可以使用 EventQueue.invokeLater() 追加 Runnable 在所有未决事件之后。其结果类似于c DoEvents() 在你输入代码之前 Runnable.run() 方法。

    See Java documentation for EventQueue .

    例如,如果要让所有GUI控件失去焦点并执行它们的失去焦点事件,可以使用以下代码:

    @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...
            }
        });
    }
    
        3
  •  0
  •   Michael Spector    15 年前

    它被称为事件循环。这个 article 演示如何在Java中的UI组件中处理事件。