FileDocCategorySizeDatePackage
SerializedScribble.javaAPI DocExample8688Mon Sep 22 13:30:32 BST 1997None

SerializedScribble

public class SerializedScribble extends Frame
This class demonstrates the use of object serialization to provide a file format for saving application state. It saves a user's scribbles as a compressed, serialized Vector of Line objects.

Fields Summary
Constructors Summary
public SerializedScribble()
Create a Frame, Menu, and Scribble component

    super("SerialziedScribble");             // Create the window.

    final Scribble scribble;
    scribble = new Scribble(this, 300, 300); // Create a bigger scribble area.
    this.add(scribble, "Center");            // Add it to the ScrollPane.

    MenuBar menubar = new MenuBar();         // Create a menubar.
    this.setMenuBar(menubar);                // Add it to the frame.
    Menu file = new Menu("File");            // Create a File menu.
    menubar.add(file);                       // Add to menubar.

    // Create three menu items, with menu shortcuts, and add to the menu.
    MenuItem load, save, quit;
    file.add(load = new MenuItem("Load"));
    file.add(save = new MenuItem("Save"));
    file.addSeparator();                     // Put a separator in the menu
    file.add(quit = new MenuItem("Quit"));

    // Create and register action listener objects for the three menu items.
    load.addActionListener(new ActionListener() {     // Open a new window
      public void actionPerformed(ActionEvent e) { scribble.load(); }
    });
    save.addActionListener(new ActionListener() {     // Close this window.
      public void actionPerformed(ActionEvent e) { scribble.save(); }
    });
    quit.addActionListener(new ActionListener() {     // Quit the program.
      public void actionPerformed(ActionEvent e) { System.exit(0); }
    });

    // Another event listener, this one to handle window close requests.
    this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) { System.exit(0); }
    });

    // Set the window size and pop it up.
    this.pack();
    this.show();
  
Methods Summary
public static voidmain(java.lang.String[] args)
A very simple main() method for our program.

 new SerializedScribble();