[Advanced-java] Updation of ProgressBar??
Bikash Paul
bikashpaul_2001 at yahoo.com
Tue May 27 13:05:01 2003
Hi all friends,
Iam facing problem with updation of progressBar of my
swing Interface.I want to update my progressBar by the
bytes which is already written by server on
destination.It is basically a uploading software.For
that iam using a thread and i have written a method of
taking the bytes from servlet.And in servlet iam
writting bytes by 'PrintWriter' in loop.But I couldn't
update progressBar.Can any one plz guide me where i am
wrong in my code.If possible plz give me some code for
that.Iam pasting those portion of codes only.Eagerly
waiting for someone reply.
In servlet:-
==========
PrintWriter out=response.getWriter();
for(cc = dis.read(buf, 0, 1024); cc > 0 ; cc =
dis.read(buf, 0, 1024))
{
if(checkpath.exists()){
os.write(buf, 0, cc);
tot += cc;
out.println(tot);
if (str.equals(str1)) break;
}
else{
out.println("Connection Broken");
break;
}
Swing interface:-
===============
public static void updateprogress(){
int ln;
int tot=0;
String str;
try{
BufferedReader input = new BufferedReader (new
InputStreamReader(con.getInputStream ()));
while ((str=input.readLine())!=null)
{
ln=Integer.parseInt(str);
tot += ln;
progressBar.setValue(tot);
}input.close();
}
catch(Exception exp) {
System.out.println("Error:" + exp.toString());
}
}
And Iam calling this method in my another method
through which iam uploading file.
myThread1 = new Thread (){
public void run () {
while (true) {
updateprogress();
try{
this.sleep (10000);
}
catch(Exception nx){}
}
}
};
myThread1.start();
Regards
Bikash
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com