// This example is from _Java Examples in a Nutshell_. (http://www.oreilly.com)
// Copyright (c) 1997 by David Flanagan
// This example is provided WITHOUT ANY WARRANTY either expressed or implied.
// You may study, use, modify, and distribute it for non-commercial purposes.
// For any commercial use, see http://www.davidflanagan.com/javaexamples
import java.awt.*;
import java.awt.event.*;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
/** A convenience class to automatically create localized menu panes */
public class SimpleMenu {
/** The convenience method that creates menu panes */
public static Menu create(String bundlename,
String menuname, String[] itemnames,
ActionListener listener, boolean popup) {
// Get the resource bundle used for this menu.
ResourceBundle b = ResourceBundle.getBundle(bundlename);
// Get the menu title from the bundle. Use name as default label.
String menulabel;
try { menulabel = b.getString(menuname + ".label"); }
catch(MissingResourceException e) { menulabel = menuname; }
// Create the menu pane.
Menu m;
if (popup) m = new PopupMenu(menulabel);
else m = new Menu(menulabel);
// For each named item in the menu.
for(int i = 0; i |