FileDocCategorySizeDatePackage
ActionExample.javaAPI DocExample2170Thu Oct 24 20:14:20 BST 2002None

ActionExample

public class ActionExample extends JPanel

Fields Summary
public JMenuBar
menuBar
public JToolBar
toolBar
Constructors Summary
public ActionExample()

    super(true);

    // Create a menu bar and give it a bevel border.
    menuBar = new JMenuBar();
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));

    // Create a menu and add it to the menu bar.
    JMenu menu = new JMenu("Menu");
    menuBar.add(menu);

    // Create a toolbar and give it an etched border.
    toolBar = new JToolBar();
    toolBar.setBorder(new EtchedBorder());

    // Instantiate a sample action with the NAME property of
    // "Download" and the appropriate SMALL_ICON property.
    SampleAction exampleAction = new SampleAction("Download",
                                     new ImageIcon("action.gif"));

    // Finally, add the sample action to the menu and the toolbar.
    // These methods are no longer preferred:
    // menu.add(exampleAction);
    // toolBar.add(exampleAction);
    // Instead, you should create actual menu items and buttons:
    JMenuItem exampleItem = new JMenuItem(exampleAction);
    JButton exampleButton = new JButton(exampleAction);
    menu.add(exampleItem);
    toolBar.add(exampleButton);
  
Methods Summary
public static voidmain(java.lang.String[] s)

    ActionExample example = new ActionExample();
    JFrame frame = new JFrame("Action Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(example.menuBar);
    frame.getContentPane().add(example.toolBar, BorderLayout.NORTH);
    frame.setSize(200,200);
    frame.setVisible(true);