• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Countdown timer in java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have two classes in java and am attempting to countdown to 0. I cannot change the code in minute second display and am having difficulty getting it to move from 10 to 0 on the display in minute second display because it calls invokeLater to Update the display and that does no get done until the end. If you could look at my code and give me any advice I would appreciate it.



 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are calling the countdown() method directly from the actionPerformed() method, which executes in your event dispatch thread - the same thread to used to draw on the screen. Since you are performing the Thread sleeping inside countdown the Event Thread won't be able to do the work it is intended to do - update the GUI.

So you should move the countdown() code to a different thread, so that the GUI interface isn't blocked while counting.

You are also doing some redundant context switching (with SwingUtilities.invokeLater() to call a method that itself uses SwingUtilities.invokeLater()), and creating objects you don't use (for example the t = new Thread(count)). So your code has a lot of clean-up which can be done.
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic