This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Progress Percentage Problem

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am making an application that downloads updates from the Internet. It should update a JProgressBar appropriately as the download proceeds. There is the point of interest:



Here this is the output:



Please, but why is it stuck at 0% then jump t0 100% yet the gradual progress is clear? Why doesn't it update?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is here

Suppose totalInInt is 100 and downloadedInInt is 12. Now 12/100 = 0.12 but as you are using ints this will be rounded to 0. You then multiply this by 100 and get 0. This will be the result until downloadedInInt and totalInInt are equal when the division will give you 1 as a result.
Do the multiplication first and it should work

 
Arthur Buliva
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a million for the clarification, Joanne. That has worked.
 
Arthur Buliva
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, Here is my terminal output:



I now face this problem; The progress bar does not gradually update, but instead "hangs" till the updating gets to 100%, then it shows 100%

This is the updated code:



 
Have you no shame? Have you no decency? Have you no tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic