Progress Dialog Help
I am having trouble implementing a ProgressMonitor dialog window in my
java application. The application is designed to ask the user to
enter a value in a screen. This value is then placed into a HTTP
request and sent to a web server, the XML result is parsed and then
displayed on the screen to the user in a very nice graphical layout.
When the user hits the "Lookup" button on my form, it calls the
following function
// getWebServiceResponse
//
// Executes an HTTP post request to the host with the designated
// request and returns a response string. If the response is null,
// the web service did not return data or request failed.
//
String response getWebServiceResponse(String host, String request) {
String response;
PostMethod post = new PostMethod(host);
post.setRequestEntity(new StringRequestEntity(request));
post.setRequestHeader("Content-type", "text/xml");
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
try {
int result = client.ExecuteMethod(post);
DataInputStream dis = new
DataInputStream(post.getResponseBodyAsStream());
StringBuffer sb = new StringBuffer();
String line = null;
while((line = dis.readLine()) != null) { sb.append(line+"\n"); }
response = sb.toString();
} catch (ConnectionTimeoutException e) {
System.out.println("Remote web server timed out.");
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
} finally {
post.releaseConnection();
}
return(response);
}
Now this function is a method within my JFrame class. What I want to
do is to wrap this function so that I can place a ProgressMonitor
dialog up for the user when this function is called and have it start
ticking from 1% to 100%. If the progress monitor reaches 99% and the
request hasn't ended yet, it would stay at 99% until it either times
out or completes.
Can anyone offer a code sample/rewrite of my above code in order to
implement such a dialog?