Java Reference
In-Depth Information
{
/** Constructor passes title to super class. **/
public FrameMenuApp (String title) {
super (title);
}
/** Create a frame and display image with DrawingPanel. **/
public static void main (String[] args) {
// Get an image and pass it to an instance of DrawingPanel.
Image img
=
Toolkit.getDefaultToolkit ().getImage (
"Apollo16Lander.jpg");
DrawingPanel drawingPanel = new DrawingPanel (img);
// Create an instance of this JFrame subclass.
FrameMenuApp f
=
new FrameMenuApp (
"
Frame with Menu Bar Demo
"
);
f.setDefaultCloseOperation (JFrame.EXIT
-
ON
-
CLOSE);
// Build a menu bar.
JMenuBar mb = new JMenuBar ();
// Create a standard "File" drop-down menu.
JMenu menu = new JMenu ("File");
// Include for key selection of the menu item.
menu.setMnemonic (KeyEvent.VK
-
F);
// Add the menu to the menu bar
mb.add (menu);
// Create an Open item for the menu.
JMenuItem menuOpen = new JMenuItem ("Open", KeyEvent.VK
-
O);
menu.add (menuOpen);
// The FrameMenuApp implements ActionListener
// to respond to the menu item selections.
menuOpen.addActionListener (f);
// Include a separate line on the menu.
menu.addSeparator ();
// Add the exit item
JMenuItem menuExit
=
new JMenuItem (
"
Exit
"
, KeyEvent.VK
-
X);
// Includes the accelerator key combo to select it.
menuExit.setAccelerator (KeyStroke.getKeyStroke (
Search WWH ::
Custom Search