Create an About Menu Item in Java
Description
The following code shows how to create an About Menu Item.
Example
//from w ww .j av a2 s . c om
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class Main extends JFrame {
public Main(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) {
Main window = new Main("Sketcher");
window.setBounds(30, 30, 300, 300);
window.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »