package dk.daoas.fulddaekning; public class ProgressBar { int total = 0; int current = 0; public ProgressBar(int total) { this.total = total; } public synchronized void tick() { current ++; if ( (current%25) == 0) { updateProgress( ((double)current) / total ); } } private void updateProgress(double progressPercentage) { StringBuilder sb = new StringBuilder(); final int width = 50; // progress bar width in chars sb.append("\r["); int i = 0; for (; i <= (int)(progressPercentage*width); i++) { sb.append("."); } for (; i < width; i++) { sb.append(" "); } sb.append("] "); sb.append( String.format("%5.1f",progressPercentage*100) ); sb.append("% "); System.out.print( sb.toString() ); } }