计算机外文翻译--菜单和工具栏(编辑修改稿)内容摘要:

ost certain to cause confusion and usability challenges for your users。 having multiple menu bars would be baffling. Properties The properties of the JMenuBar class are shown inTable 143. menu is an indexed property that references eachJMenu attached to the menu bar. The readonly menuCount property maintains a count of these attached menus. Remember that the single selection model allows only one menu to be activated at a time. If any menu is currently activated, the selected property returns true。 otherwise, the property returnsfalse. TheponentAtIndex property accesses the menu associated with the given index. It is similar to the indexed menu property, except the contents are cast to 4 aComponent. If there is no ponent associated with that index, the getComponentAtIndex( ) accessor returns null. Theponent property returns a reference to this (., the menu bar itself)。 subElements returns an array consisting of the menus on the menu bar. The JMenuItem Class Event Handling There are a number of ways to process events from menu items. Because menu items inherit ActionEvent functionality from AbstractButton, one approach is to assign an action mand to each menu item (this is often done automatically with named ponents) and attach all of the menu items to the same ActionListener. Then, in theactionPerformed( ) method of the listener, use the event39。 s getActionCommand( ) method to obtain the action mand of the menu item generating the event. This tells the listener which menu item has been clicked, allowing it to react accordingly. This is the approach used in earlier in this chapter , which is discussed later. Alternatively, you can register a separate ActionListener class with each menu item, which takes the guesswork out of determining the menu item selected. However, Swing allows you to go a step further. The most objectoriented approach is to create a specialized Action class that corresponds to each of the tasks a user might request of your application. This lets you bundle the code for each program action together with the action39。 s name, icon, keystrokes, and other attributes in on。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。