Java Tutorial/Swing/ProgressMonitorInputStream — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 18:31, 31 мая 2010
14. ProgressMonitorInputStream
Represent an input stream filter that uses a ProgressMonitor to check the progress of the reading of an input stream.
<source lang="java">
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; import javax.swing.JLabel; import javax.swing.ProgressMonitorInputStream; public class ProgressInputSample {
public static final int NORMAL = 0; public static final int BAD_FILE = 1; public static final int CANCELED = NORMAL; public static final int PROBLEM = 2; public static void main(String args[]) { int returnValue = NORMAL; try { FileInputStream fis = new FileInputStream("person.xml"); JLabel filenameLabel = new JLabel("persion.xml", 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 (Exception exception) { returnValue = PROBLEM; } System.exit(returnValue); }
}</source>