|
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
Q&AQ 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, youll want to specify the text in the menu constructor. For each menu item, youll need to add the menu entries. The menu entries are the text that will appear under the menu items. You simply use the Menu classs add() method to add the menu entries. You then use the MenuBars add() method to add the menu items to it. Finally, after the entire menu is created, use the Frame windows 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 classs 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 youve added a window to your applications 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 its not, you wont 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, dont. 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. Theyre 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
|
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. |