// This example is from the book Developing Java Beans by Robert Englander.
// Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.
// Chapter 5 -- The Example8 class
import java.awt.*;
import java.io.*;
public class Example8
{
protected Frame fr;
public void init(String cmd)
{
fr = new Frame("Example8");
if (cmd.equals("save"))
{
ListeningPanel p = new ListeningPanel();
p.initialize();
fr.add(p);
fr.setVisible(true);
fr.reshape(100,100,300,100);
fr.repaint();
try
{
FileOutputStream f = new FileOutputStream("Example8.tmp");
ObjectOutput s = new ObjectOutputStream(f);
s.writeObject(p);
s.flush();
}
catch (Exception e)
{
System.out.println(e);
}
}
else if (cmd.equals("restore"))
{
try
{
FileInputStream f = new FileInputStream("Example8.tmp");
ObjectInput s = new ObjectInputStream(f);
ListeningPanel p = (ListeningPanel)s.readObject();
fr.add(p);
fr.setVisible(true);
fr.reshape(100,100,300,100);
fr.repaint();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
public static void main(String[] args)
{
Example8 a = new Example8();
a.init(args[0]);
}
}
|