java button pressed for 3 seconds

前端 未结 5 665
太阳男子
太阳男子 2021-01-21 16:22

I created a button and I want these:

When the user clicks the button, it stays pressed like 3 seconds. After 3 seconds the button should be again look pressable. So the

5条回答
  •  独厮守ぢ
    2021-01-21 17:14

    Try disabling it, putting the thread to sleep for three seconds, then enable it again:

    private void setPressedIcon(){
     try {
      button3.setEnabled(false);
      Thread.sleep(3000);
     } catch(InterruptedException e) {
     } finally {
       //reenable the button in all cases
       button3.setEnabled(true);
    } 
    

提交回复
热议问题