Timer Program.. please help!
I'm trying to program an application in Java that shows a JTextField to countdown from 59 to 0, and once it hits 0, go back to 59 again.
I'm having trouble to just trying to initialize to countdown, and after having tried so many things, I really need someone to put me in the right direction since this is my first time using event listeners and the Timer class in Java.
Here is the version of my program that compiles:
I tried setting up a final variable and then updating it within the Click event but I get a syntax error since a final variable cannot be changed. I also tried initializing an int variable to 59 within the Click event but each time the timer goes off, the text field only shows 59 since it's a local variable.
This program demonstrates how to install an action listener to a timer event to countdown from 59 to 0 and then back again.
public class Button
public static void main(String args)
JFrame frame = new JFrame();
JLabel label = new JLabel("Time remaining: ");
final JTextField textField = new JTextField("59", 4);
JPanel panel = new JPanel();
class Click implements ActionListener
public void actionPerformed(ActionEvent click)
for(int i = 59; i > 0; i--)
String textCounter = Integer.toString(i);
Click listener = new Click();
Timer t = new Timer(1000, listener);
Can anyone please help?