如何通過按下一個按鈕來禁用按鈕,以及當按下的按鈕被分配給的任務已完成時,我希望啓用所有按鈕。例如;如何在java,eclipse中啓用/禁用按鈕?
UpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DownButton.setEnabled(false);
LeftButton.setEnabled(false);
RightButton.setEnabled(false);
System.out.printline("Up Button");
}
});
DownButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UpButton.setEnabled(false);
LeftButton.setEnabled(false);
RightButton.setEnabled(false);
System.out.printline("Down Button");
}
});
LeftButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DownButton.setEnabled(false);
UpButton.setEnabled(false);
RightButton.setEnabled(false);
System.out.printline("Left Button");
}
});
RightButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DownButton.setEnabled(false);
LeftButton.setEnabled(false);
UpButton.setEnabled(false);
System.out.printline("Right Button");
}
});
我試過這樣做,但它不起作用。我想要的是,例如,我的Upbutton正在打印(「向上按鈕」),所以當用戶按下此按鈕時,我希望所有其他按鈕都被禁用,直到它完成了它應該執行的命令爲止,在這種情況下打印出一個文本,但稍後我會添加諸如添加兩個用戶輸入的內容我會有一個按鈕,要求用戶鍵入數字1然後數字2,然後計算機將它們添加並在此過程中,我希望所有的按鈕被禁用,期望已被點擊的按鈕,直到用戶已經給出了所有的數字,並且計算機已經給出了輸出。
我希望我已經正確地解釋了自己,如果不是,請讓我知道,我會盡我所能提供更多信息。提前致謝。
只是一個問題,請這個問題是關於.... – mKorbel
點後不可能使用代碼標籤(從來沒有動手,也許有人這樣做與HTML格式) – mKorbel
使用JRadioButtons添加到ButtonGroup,很少費力可以通過使用JToggleButtons – mKorbel