java set delay to change imageicon

前端 未结 2 535
猫巷女王i
猫巷女王i 2021-01-29 10:11

i\'m trying to set a delay when a button is pressed to set an imageicon to a certain image then set another delay so that another image would be set, all of this by single click

2条回答
  •  旧时难觅i
    2021-01-29 11:15

    1. don't add MouseListener to JButton, nor for mouseClicked(), add ActionListener instead, btw all Mouse and Key events are implemented in JButton API and correctly

    2. don't to use Thread.sleep(n); you have an issue with Concurency in Swing, use Swing Timer instead,

提交回复
热议问题