How to make Timer countdown along with progress bar?

前端 未结 3 1590
迷失自我
迷失自我 2020-12-11 22:14

How can I make it so that the progress bar slowly goes down with the time limit?

class GamePanel extends JPanel implements MouseListener, ActionListener
{
           


        
3条回答
  •  無奈伤痛
    2020-12-11 22:56

    That is definitely too much information, and a very broad question. I'd say at most you only need to include the code for the class where the timer is, and the class where the progress bar gets drawn.

    From skimming the code, I'm guessing you're using a rectangle to draw the progress bar. Based on that, one way you could go about it would be using a variable to store the width of the bar, and every time the timer ticks, decrease the width of the bar by a set amount. Then just set the width of the rectangle drawn to the value stored in the variable.

提交回复
热议问题