1

如果我想等待用户交互(在用户按下某个按钮时等待),只是想确保这种方法是否正确:

SomeDialog someDialog = new SomeDialog(frame);

someDialog.setVisible(true);

try {

       synchronized (someDialog) {
          someDialog.wait();
       }

     } catch (InterruptedException ex) {
       Logger.getLogger(SomeDialog.class.getName()).log(Level.SEVERE, null, ex);
     }

int a = 0; a++; // <---- this line should not be processed before user clicks a button

接着:

someDialogButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

    synchronized (SomeDialog.this) {
       SomeDialog.this.notify();
    }

  }
});
4

1 回答 1

0

someDialog.setModal(true)如果您需要等待用户在执行其他操作之前处理您的对话框,请使用to。

于 2013-10-14T11:24:42.287 回答