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();