animating progress bar--- creating according to the installation

the following code , which shows hot use the progressbar in the java swing... it uses the swing worker to animate its progress while installing or doing some updations....

refer this link for further doubts...
swingworker:http://java.sun.com/docs/books/tutorial/uiswing/concurrency/simple.html

/**
this class progress is used to create to update the value by swing worker to the process method.
this class type is mentioned in the swing worker it has two type of parameter, first shows the done method, and it should be overridden. the second parameter specifies the this call, and u should override the process method..
*/
private static class Progress {

private final double barValue;

Progress(double barValue) {
this.barValue = barValue;
}
}

private class processTask extends SwingWorker {

@Override
protected Void doInBackground() throws Exception {
progressBar.setIndeterminate(false);
double previousval = 0;
try {
completeStatus = false;
getClientComponents();
boolean status = false;
Set machineKey = machinesMap.keySet();
Iterator machineIterator = machineKey.iterator();
int noofMachine = machineKey.size();
double inc = 100 / (double) totalClients;
System.out.println("the inc value is_--------_____>" + inc);
int count = 0;
while (machineIterator.hasNext()) {
status = deployer.installClientComponent(machinesMap.get(machineIterator.next()));
count++;
double sum = 0;
if (status) {
progressval += inc;
completeStatus = true;
System.out.println("installed " + progressval);
System.out.println("no of machine is " + count);
while (previousval < progressval) {

Thread.sleep(1000);
publish(new Progress(previousval++));
}


} else {
progressval += inc;
}
previousval = progressval;
Thread.sleep(2000);
}
if (completeStatus) {
String str = "" + "" + "" + "Installation Process Copleted.........." + "" + "" + "";
progressLabel.setText(str);
next.setEnabled(true);
installClientButton.setEnabled(false);
stpInstallerToolView.finishInstallation(true);

} else {

String str = "" + "" + "" + "Installation Process Failed......Please Select a Component for Install" + "" + "" + "";
progressLabel.setText(str);
}
} catch (Exception e) {
System.out.println("error" + e.getMessage());
}


return null;

}

@Override
protected void process(List val) {
super.process(val);
Progress pro = val.get(val.size() - 1);
progressBar.setValue((int) Math.round(pro.barValue));
}
}

Comments

Popular posts from this blog

Spring MVC with Sqlite sample

Struts Tutorial Page