import java.awt.*; import javax.swing.*; import java.awt.event.*; class TestMenuBar { /* Declare two arrays, one of string names, * one of matching Colors. */ private static final String colorNames[] = { "Black", "Blue", "Cyan", "Dark Gray", "Gray", "Green", "Light Gray", "Magenta", "Orange", "Pink", "Red", "White", "Yellow"}; private static final Color colors[] = { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow }; /* Pane that holds the contents of the frame. */ private static Container pane; public static void main(String[] args){ /* Create a JFrame, set title, and get contents pane. */ JFrame frame = new JFrame(); frame.setTitle("Adding Menus"); pane = frame.getContentPane(); pane.setLayout(new FlowLayout()); /* Create the menu bar, and add two menus */ JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic('F'); menuBar.add(fileMenu); JMenu optionsMenu = new JMenu("Options"); optionsMenu.setMnemonic('O'); menuBar.add(optionsMenu); /* Add the menu bar to the frame */ frame.setJMenuBar(menuBar); /* Add a menu item to options */ JMenu background = new JMenu("Background"); background.setMnemonic('B'); /* Add the colors to the sub menu. * Create first an ActionListener to listen to events. */ ActionListener al = new ActionListener(){ public void actionPerformed(ActionEvent e){ for(int i = 0; i