Java Reference
In-Depth Information
public static void main(String args[]) {
int returnValue = NORMAL;
if (args.length != 1) {
System.err.println("Usage:");
System.err.println("java ProgressInputSample filename");
} else {
try {
FileInputStream fis = new FileInputStream(args[0]);
JLabel filenameLabel = new JLabel(args[0], JLabel.RIGHT);
Object message[] = { "Reading:", filenameLabel} ;
ProgressMonitorInputStream pmis =
new ProgressMonitorInputStream(null, message, fis);
InputStreamReader isr = new InputStreamReader(pmis);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
} catch (FileNotFoundException exception) {
System.err.println("Bad File " + exception);
returnValue = BAD_FILE;
} catch (InterruptedIOException exception) {
System.err.println("Canceled");
returnValue = CANCELED;
} catch (IOException exception) {
System.err.println("I/O Exception " + exception);
returnValue = PROBLEM;
}
}
// AWT Thread created - must exit
System.exit(returnValue);
}
}
■
Note
Having a
null
argument for the parent component to the
ProgressMonitorInputStream
constructor causes the pop-up window to appear centered on the screen.
ProgressMonitorInputStream Properties
Table 9-7 shows the single property of
ProgressMonitorInputStream
. The
ProgressMonitor
is
created when the input stream is created. You shouldn't need to modify the
ProgressMonitor
.