We can also develop an application with a Menu. As a name indicates a Menu consists of Menu objects. These Menu objects comprise of MenuItem objects which can be selected by the user with a click of a mouse. A MenuItem may be a String, checkbox, separator, menu etc.
Following are the steps to to add menus to any Frame:
MenuBar mb = new MenuBar();
2. Then you need to create a Menu using Menu m = new Menu("File");.
3. Now the MenuItem options can be added to the Menu from top to bottom, using the following methods.
mi.add(new CheckboxMenuItem("Type here"));
4. Now you can add the Menu to the MenuBar from left to right using mi.add(m);.
5. Finally, you need
to add the MenuBar to the Frame by calling the setMenuBar() method.
The program code given below, creates an application window with a menu bar.
Output of the program:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial