FileDocCategorySizeDatePackage
ProgressMeterStrmDemo.javaAPI DocExample1651Sun Mar 11 21:28:36 GMT 2001None

ProgressMeterStrmDemo

public class ProgressMeterStrmDemo extends JFrame implements Runnable
Demonstrate ProgressMeterInputStream.
author
Ian Darwin, ian@darwinsys.com
version
$Id: ProgressMeterStrmDemo.java,v 1.3 2001/03/12 02:28:36 ian Exp $

Fields Summary
Constructors Summary
public ProgressMeterStrmDemo()

		new Thread(this).start();
	
Methods Summary
public static voidmain(java.lang.String[] av)

		ProgressMeterStrmDemo demo = new ProgressMeterStrmDemo();
		demo.setSize(100, 100);
		demo.getContentPane().add(new JLabel("ProgressMeterStrmDemo"));
		demo.pack();
		demo.setVisible(true);

	
public voidreadTheFile()

		// OK, we're going to read a file. Do it...
		FileInputStream is = new FileInputStream("index.htm");
		BufferedReader ds = new BufferedReader(
			new InputStreamReader(
				new ProgressMonitorInputStream(this,
					"Loading...", new FileInputStream("index.htm"))));

		// Now read it...
		String line;
		while ((line = ds.readLine()) != null) {
			if (System.getProperties().getProperty("debug.lines")!=null)
				System.err.println("Read this line: " + line);
			try {
				Thread.sleep(200);		// slow it down a bit.
			} catch(InterruptedException e) {
				return;
			}
		}
		// Close file, since it was opened.
		ds.close();
	
public voidrun()
We use a separate "thread" (see Threads chapter) to do the reading, so the GUI can run independantly (since we have "sleep" calls to make it appear to run more slowly).

		try {
			readTheFile();
		} catch (EOFException nme) {
			return;
		} catch (IOException e) {
			System.err.println(e.toString());
			return;
		}