FileDocCategorySizeDatePackage
Mnemonic.javaAPI DocExample1529Mon Nov 09 12:45:54 GMT 1998None

Mnemonic

public class Mnemonic extends JFrame

Fields Summary
private JPanel
buttonPanel
Constructors Summary
public Mnemonic()


    buttonPanel.setLayout(new GridLayout(1, 4, 4, 4));

    // Create the buttons.
    addButton("Sports", new ImageIcon("images/sports.gif"));
    addButton("Music", new ImageIcon("images/music.gif"));
    addButton("Travel", new ImageIcon("images/travel.gif"));
    addButton("Art", new ImageIcon("images/art.gif"));

    // Layout.
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    c.add(new JLabel("Select an Activity"), BorderLayout.NORTH);
    c.add(buttonPanel, BorderLayout.CENTER);
    pack();
  
Methods Summary
private voidaddButton(java.lang.String label, javax.swing.Icon icon)


    // Use the first char as our key mnemonic
    final char key = label.charAt(0);
    JButton button = new JButton(label, icon);

    // this will register keystrokes with the ALT mask
    button.setMnemonic(key);
    button.setVerticalTextPosition(SwingConstants.BOTTOM);
    button.setHorizontalTextPosition(SwingConstants.CENTER);

    // add this button to the panel
    buttonPanel.add(button);
  
public static voidmain(java.lang.String[] args)


  // A simple test program
       
    Mnemonic acc = new Mnemonic();
    acc.setVisible(true);