⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 12_7_1.htm

📁 翁剀JAVA语言那门课程的教案 很多人都看多他的视频教程可惜没有ppt的教案
💻 HTM
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"><html><head>   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">   <meta name="Author" content="Weng Kai">   <meta name="GENERATOR" content="Mozilla/4.5 [en] (Win95; I) [Netscape]">   <title>Menus</title></head><body><h3>12.7.1 Menus</h3><hr WIDTH="100%"><br>It's impossible to put a menu directly on an applet (in Java 1.0 andJava 1.1; the Swing library does allow it), so they're for applications.Go ahead, try it if you don't believe me and you're sure that it wouldmake sense to have menus on applets. There's no <b>setMenuBar( )</b> methodin <b>Applet</b> and that's the way a menu is attached. (You'll see laterthat it's possible to<br>spawn a <b>Frame</b> from within an <b>Applet</b>, and the <b>Frame</b>can contain menus.)<p>There are four different types of <b>MenuComponent</b>, all derivedfrom that abstract class: <b>MenuBar</b> (you can have one <b>MenuBar</b>only on a particular <b>Frame</b>), <b>Menu</b> to hold one individualdrop-down menu or submenu, <b>MenuItem</b> to represent one single elementon a menu, and <b>CheckboxMenuItem</b>, which is derived from <b>MenuItem</b>and produces a checkmark to indicate whether that menu item is selected.<p>Unlike a system that uses resources, with Java and the AWT you musthand assemble all the menus in source code. Here are the ice cream flavorsagain, used to create menus:<p>Case Study: <a href="case/Windows/Menu1.java">Menu1.java</a><p>In this program I avoided the typical long lists of <b>add( )</b> callsfor each menu because that seemed like a lot of unnecessary typing. Instead,I placed the menu items into arrays and then simply stepped through eacharray calling <b>add( )</b> in a <b>for</b> loop. This makes adding orsubtracting a menu item less tedious.<p>As an alternative approach (which I find less desirable since it requiresmore typing), the <b>CheckboxMenuItems</b> are created in an array of handlescalled safety; this is true for the arrays file and other as well.<p>This program creates not one but two <b>MenuBars</b> to demonstratethat menu bars can be actively swapped while the program is running. Youcan see how a <b>MenuBar</b> is made up of <b>Menus</b>, and each <b>Menu</b>is made up of <b>MenuItems</b>, <b>CheckboxMenuItems</b>, or even other<b>Menus</b>(which produce submenus). When a <b>MenuBar</b> is assembled it can beinstalled into the current program with the <b>setMenuBar( )</b> method.Note that when the button is pressed, it checks to see which menu is currentlyinstalled using <b>getMenuBar( )</b>, then puts the other menu bar in itsplace.<p>When testing for "Open",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -