// 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 PickleSaver class
import java.applet.*;
import java.awt.*;
import java.io.*;
import BeansBook.util.*;
public class PickleSaver extends Applet
{
public void init()
{
// create an instance of PickleButton
PickleButton b = new PickleButton();
// set the properties
Font ft = new Font("System", Font.BOLD, 36);
b.setFont(ft);
b.setLabel("Sour Pickle");
// serialize the pickle button
try
{
FileOutputStream f = new FileOutputStream("PickleButton.ser");
ObjectOutputStream s = new ObjectOutputStream(f);
s.writeObject(b);
s.flush();
}
catch (Exception e)
{
System.out.println(e);
}
add(b);
}
}
|