Menu in Java AWT example: This Java AWT menu tutorial is used to create a menu and menu items in a Drop down manner. This drop down menu looks like normal Windows menu bar. If you want to create your own menu bar, then this simple AWT tutorial will help you. An example program is given below.
MENU BAR IN JAVA
This java program is used to create a menu bar like all windows application menus. We have included all the function like new, open, close, save, save as, exit and we also extend the coding to ensure paste, cut and copy also. We used this menu bar as a notepad clone and word pad clone.
[Useful: C Program Tutorials] & [IT Companies Details]
Java AWT example Tutorial:
Q: Write a Java code for creating menus and menu items using AWT example.
//Import statements import java.awt.*; import java.awt.event.*; class MenuDemo extends Frame { //Variable declaration MenuBar mr; Menu fe; MenuItem n1, o, s, ss, et; //Main Class public MenuDemo(String title) { super(title); mr=new MenuBar();//Object creation fe=new Menu("File"); n1=new MenuItem("New"); o=new MenuItem("Open..."); s=new MenuItem("Save"); ss=new MenuItem("Save As..."); et=new MenuItem("Exit"); fe.add(n1); fe.add(o); fe.addSeparator(); fe.add(s); fe.add(ss); fe.addSeparator(); fe.add(et); mr.add(fe); setMenuBar(mr); setSize(300,300); show(); } public static void main(String args[]) { new MenuDemo("Menus Demo"); } }
SEE: All Examination Results & News