3

I need a countdown timer that does a task every second (change a label's text so it appears to be counting down). I've looked at a lot of the Java docs and also at examples online but I don't really understand any of them (I'm new to programming) so If you could explain in simple terms that would be great!

I've started off by making a Timer timer; and then timer = new Timer() when I want it to start, now I'm stuck :(

JL9
  • 533
  • 3
  • 17
  • 1
    I would not recommend using graphical programming systems like BlueJ, I find it nearly impossible to learn from. Use an IDE like Eclipse. – CaffeineToCode Apr 07 '15 at 23:21
  • 1
    I heard Eclipse is a lot better, unfortunately I'm a student and the university says we must use BlueJ. – JL9 Apr 07 '15 at 23:35
  • Your university is very poor if they say that you absolutely have to use BlueJ... it is not even a real IDE. Where are you going to school? – CaffeineToCode Apr 08 '15 at 00:31
  • 1
    Our university made bluej, that's why - University of Kent -.- I'm only in my first year, I think next year we move onto Eclipse, thank god, I hate BlueJ! – JL9 Apr 08 '15 at 00:35
  • //static int i = 0; JFrame frame = new JFrame(); JLabel label = new JLabel("0"); frame.add(label); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); Timer timer = null; ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { label.setText(++i+" "); } }; timer = new Timer(1000, listener); timer.start(); –  Apr 08 '15 at 13:04
  • That should be in an answer, not a comment. – CaffeineToCode Apr 08 '15 at 18:31

0 Answers0