Java Swing How to - Create an About Menu Item








Question

We would like to know how to create an About Menu Item.

Answer

/*from  ww w  .  j a  v a  2  s  .  co m*/
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class FramewithAboutMenu extends JFrame {
  public FramewithAboutMenu(String title) {
    JMenuBar menuBar = new JMenuBar();
    setTitle(title);
    setJMenuBar(menuBar);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JMenu fileMenu = new JMenu("File");
    JMenu elementMenu = new JMenu("Elements");
    JMenu helpMenu = new JMenu("Help");
    fileMenu.setMnemonic('F');
    elementMenu.setMnemonic('E');
    helpMenu.setMnemonic('H');
    JMenuItem aboutItem = new JMenuItem("About");
    helpMenu.add(aboutItem);
    menuBar.add(helpMenu);
  }
  public static void main(String[] a) {
    FramewithAboutMenu window = new FramewithAboutMenu("Sketcher");
    window.setBounds(30, 30, 300, 300);
    window.setVisible(true);
  }
}