小编use*_*690的帖子

按下方法等待按钮

我的方法必须在用户按下按钮后返回.经过一些研究,我认为这样可行:

方法本身:

public Aluno getAlunoFromUser() throws InterruptedException
{
    //Wait to be notified from ActionListener
    synchronized(this)
    {
        this.wait();
    }

    //return
    return null;
}
Run Code Online (Sandbox Code Playgroud)

ActionListener:

Button.addActionListener( 
            new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    this.notify();
                }
            });
Run Code Online (Sandbox Code Playgroud)

但该计划正在冻结.我想知道如何解决这个问题.

java concurrency swing wait

2
推荐指数
1
解决办法
601
查看次数

标签 统计

concurrency ×1

java ×1

swing ×1

wait ×1