Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Sams Teach Yourself Visual J++ 6 in 21 Days
(Publisher: Macmillan Computer Publishing)
Author(s): Rick Leinecker
ISBN: 0672313510
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Q&A

Q Can you add a menu to an applet window?

A Not to the main applet window. You must create a Frame window first. You can add a menu bar to a Frame window in an applet.

Q How do you create a menu bar to add to an applet Frame window?

A Here are the steps: First, create a MenuBar object. Then, for each menu item you want, create a Menu object. When you create the Menu objects, you’ll want to specify the text in the menu constructor. For each menu item, you’ll need to add the menu entries. The menu entries are the text that will appear under the menu items. You simply use the Menu class’s add() method to add the menu entries. You then use the MenuBar’s add() method to add the menu items to it. Finally, after the entire menu is created, use the Frame window’s setMenuBar() method to add the menu bar to the Frame window.

Q How do you respond to menu events in applets?

A You have to declare a new class that implements the ActionListener interface. You then need to override the actionPerformed() method that will catch all the menu events. Then, you must use the Menu class’s addActionListener() method to add the ActionListener class you created.

Q How do you create a menu in an application?

A You simply display your Form window, select the Menu control in the Toolbox, and then place a Menu control on the Form window. After you’ve added a window to your application’s Form window, you can add menu items and menu entries.

Q How do you create a menu event handler for an application?

A You select a menu entry you want to create an event handler for. You double-click on that menu entry, or in the Property window with the event button selected, double-click on the click event. You then are brought directly to the source code for the event handler for that menu entry.

Q Not all applets that you see on the Web use menus. When would it be advisable to create menus for your applets on the Web?

A The first problem with using menus in applets on the Web is that you must have a frame window that comes out on top of your main applet window. So for starters, you have to ask yourself whether having a frame window is what you want for your program. If it is, menus might be a good choice. If it’s not, you won’t want to use pull-down menus. If you decided that frame windows are okay for your applet, you must ask yourself whether you need to present some sort of a well-organized set of actions to your users. If the answer is yes, go ahead and implement pull-down menus. If the answer is no, don’t.

Q When would you ever use pop-up menus?

A Pop-up menus are common in desktop Windows applications. We normally call them context menus. They’re good for when users want more information about something in the window, or when you need to offer specific actions for some item in the window.

Review Exercises

1.  Create an applet with a frame window. Make sure that you handle the frame window’s close event. Create a menu with four items. In each item, add at least two or three entries. Add the menu to the frame window, compile the program, and run it to see what it looks like. After you’re satisfied that the program looks the way you want it, add the event handler for the menu events. Display in the frame window enough information so that the users can see what they’ve selected after they have selected it.
2.  Create an application. Put a menu in the form. Add at least four items to the form’s menu, and add at least two or three entries to each menu item. Add click event handlers for each of the menu entries. Then display text in the form window when each of the menu entries is selected.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.