Cascading Menus
As previously alluded to, cascading menus are possible with the AWT by virtue of the fact that Menu extends MenuItem. As we have seen, Menu.add(MenuItem) adds a menu item to a menu. Since a Menu is a MenuItem, the Menu.add(MenuItem) method is perfectly happy to take a Menu as an argument, which it dutifully adds to itself.
Figure 17-6 shows the cascading menu created by Example 17-9.
Figure 17-6. A Cascading Menu
Example 17-9. CascadingTest Class Listing
import java.awt.*; import java.awt.event.*; public class CascadingTest extends ... |
Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.