Source Code : Creating a menubar
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Creating a menubar
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MenuMy extends JFrame {
JMenuBar menubar = new JMenuBar();
ImageIcon icon = new ImageIcon("exit.png");
JMenu file = new JMenu("File");
public MenuMy() {
file.setMnemonic(KeyEvent.VK_F);
JMenuItem fileClose = new JMenuItem("Close", icon);
fileClose.setMnemonic(KeyEvent.VK_C);
fileClose.setToolTipText("Exit application");
fileClose.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
file.add(fileClose);
menubar.add(file);
setJMenuBar(menubar);
setSize(250, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new MenuMy();
}
}
Thank with us