FileDocCategorySizeDatePackage
ScribbleCutAndPaste.javaAPI DocExample11854Mon Sep 22 13:30:30 BST 1997None

ScribbleCutAndPaste

public class ScribbleCutAndPaste extends Frame
This class demonstrates how to implement cut-and-paste of data other than strings. It is a variant of the Scribble program we've seen so much. Only about a third of this code is directly cut-and-paste code. The rest is support code to make this an interesting example

Fields Summary
protected static int
num_windows
Remember # of open windows so we can quit when the last one is closed We support multiple windows so that we can cut-and-paste among them.
Constructors Summary
public ScribbleCutAndPaste()
Create a Frame, Menu, and ScrollPane for the scribble component


             
    
    super("ScribbleCutAndPaste");            // Create the window
    num_windows++;                           // Count it

    // Create scribble area and add to the frame
    ScribblePanel scribble = new ScribblePanel(this, 400, 300); 
    this.add(scribble, "Center");

    // Set up a menubar
    MenuBar menubar = new MenuBar();         // Create 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 n, c, q;
    file.add(n = new MenuItem("New Window", new MenuShortcut(KeyEvent.VK_N)));
    file.add(c = new MenuItem("Close Window",new MenuShortcut(KeyEvent.VK_W)));
    file.addSeparator();
    file.add(q = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q)));

    // Create and register action listener objects for the three menu items
    n.addActionListener(new ActionListener() {     // Open a new window
      public void actionPerformed(ActionEvent e) { new ScribbleCutAndPaste(); }
    });
    c.addActionListener(new ActionListener() {     // Close this window
      public void actionPerformed(ActionEvent e) { close(); }
    });
    q.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) { close(); }
    });

    // Set the window size and pop it up
    this.pack();
    this.show();
  
Methods Summary
voidclose()
Close a window. If this is the last open window, just quit.

    if (--num_windows == 0) System.exit(0);
    else this.dispose();
  
public static voidmain(java.lang.String[] args)
A very simple main() method for our program.

 new ScribbleCutAndPaste();