tailieunhanh - Introduction to Java: 10 Would You Like to Choose from the Menu?

Tham khảo tài liệu 'introduction to java: 10 would you like to choose from the menu?', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | In this chapter MenuComponent MenuContainer MenuShortcut MenuItem Menu CheckboxMenuItem MenuBar Putting It All Together PopupMenu 10 Would You Like to Choose from the Menu In Chapter 6 Containers I mentioned that a Frame can have a menu. Indeed to offer a menu in the AWT you have to attach it to a Frame. With versions and Java does not support menu bars within an applet or any other container. We hope that future versions ofJava will allow menus to be used with other containers. Java goes partway toward solving this problem by introducing a PopupMenu that lets you attach context menus to any Component. Java also adds MenuShortcut events which represent keyboard accelerator events for menus. Implementing a menu in a Frame involves connections among a number of different objects MenuBar Menu MenuItem and the optional CheckboxMenuItem. Several of these classes implement the MenuContainer interface. Once you ve created a few menus you ll probably find the process quite natural but it s hard to describe until you see what all the objects are. So this chapter describes most of the menu classes first and then shows an example demonstrating their use. All the components covered in previous chapters were subclasses of Component. Most of the objects in this chapter subclass MenuComponent which encapsulates the common functionality of menu objects. The MenuComponent class hierarchy is shown in Figure 10-1. To display a Menu you must first put it in a MenuBar which you add to a Frame. Pop-up menus are different in that they don t need a Frame. A Menu can contain MenuItem as well as other menus that form submenus. CheckboxMenuItem is a specialized MenuItem that as you might guess the user can toggle like a Checkbox. One way to visualize how all these things work together is to imagine a set of curtains. The different MenuItem components are the fabrics and panels that make up the curtains. The Menus are the curtains. They get hung from the MenuBar which is 355

TỪ KHÓA LIÊN QUAN