1
說我有SelectPieceListener'選擇'JButton。 我想檢查是否再次執行操作(單擊選擇按鈕)。 但是,actionPerformed是void,所以我不能將它用作布爾表達式。ActionListener - 如果在actionPerformed方法內調用了actionPerformed的跟蹤?
有沒有辦法做到這一點? 或者使用另一個JButton來處理這個問題會更好嗎?
謝謝。
public class SelectPieceListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if(c == _st.checkMoveImpossible()) {
System.out.println("No possible move for "+nextPlayer+": click select to skip turn, " +
"or click right to move " + t + " pieces.");
if(**the action is performed**){_board.setcmi(1);}
_board.update();
}
你能澄清一點嗎?你是否想要防止他們'actionListener'被觸發多次或知道是否在執行時再次觸發它? – MadProgrammer 2013-04-05 01:24:12
爲什麼不簡單地在ActionListener類中有一個計數器變量並在actionPerformed方法中增加它呢?我不確定我是否過度簡化了您的問題,所以如果這不能解決問題,請大大澄清一下。 – 2013-04-05 01:43:24