我試圖在按下按鈕時啓用/禁用標籤,並且希望在事件期間執行此操作,而不是在此之後執行操作。正如你可以看到下面,我嘗試啓用/禁用兩個標籤:lblKeyboard和lblGamepad。在ActionEvent期間更改標籤
它們最終會在「RemoteControl.run();」之後運行被執行,但我希望它在此之前發生。任何方式我可以做到這一點?
謝謝!在事件監聽
JButton btnGamepad = new JButton("Gamepad");
btnGamepad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(cont_state == 0){
if(RemoteControl.findGamePad() == true){
cont_state = 1;
game_status = "on";
}
else{
game_status = "off";
key_status = "on";
JOptionPane.showMessageDialog(null, "Controller not found!");
cont_state = 0;
}
}
if(cont_state == 1){
System.out.println("CONNECTED GAMEPAD!");
lblKeyboard.disable();
lblGamepad.enable();
frame.repaint();
RemoteControl.run();
cont_state = 0;
}
}
});
感謝您的幫助! SwingWorker現在對我來說非常棒!該計劃的狀態甚至比我預期的更好! – Serpace