我有 JButtons“暂停”和“取消暂停”。当用户暂停程序时,应禁用暂停按钮并启用取消暂停按钮。我不知道怎么写。取消暂停按钮有效,但暂停按钮无效,因为“无法解决取消暂停”。如何处理?这是我的代码:
final JButton pause = new JButton("Pause");
pause.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Url.pauseThread();
pause.setEnabled(false); //this works
unpause.setEnabled(true); //this does NOT work - "not resolved"
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
final JButton unpause = new JButton("Unpause");
unpause.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Url.resumeThread();
pause.setEnabled(true); // this works
unpause.setEnabled(false); // this works
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});