0% found this document useful (0 votes)
6 views2 pages

Java AWT File and Edit Menu Guide

Uploaded by

Renukadevi D
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Java AWT File and Edit Menu Guide

Uploaded by

Renukadevi D
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java AWT Program: File & Edit Menu

Objective: To create a File and Edit menu in a Java AWT application using MenuBar, Menu, and
MenuItem components.

Java Source Code:


import [Link].*; public class FileMenu { void editor() { Frame f = new
Frame("AWT Menu"); MenuBar mb = new MenuBar(); // Creating Menus Menu m1
= new Menu("File"); Menu m2 = new Menu("Edit"); // Adding items to "File"
menu MenuItem f1 = new MenuItem("New"); MenuItem f2 = new
MenuItem("Save"); MenuItem f3 = new MenuItem("Close"); [Link](f1);
[Link](f2); [Link](f3); // Adding items to "Edit" menu MenuItem e1 = new
MenuItem("Cut"); MenuItem e2 = new MenuItem("Copy"); MenuItem e3 = new
MenuItem("Paste"); [Link](e1); [Link](e2); [Link](e3); // Adding menus to
menu bar [Link](m1); [Link](m2); // Setting up Frame [Link](mb);
[Link](400, 400); [Link](null); [Link](true); } public
static void main(String args[]) { FileMenu fm = new FileMenu();
[Link](); } }

Flowchart:
1. Start → 2. Create Frame → 3. Create MenuBar → 4. Add Menus → 5. Add MenuItems → 6.
Attach MenuBar → 7. Display Frame → 8. End

Menu Structure Diagram:


MenuBar

File | Edit
↓ | ↓
New, Save, Close Cut, Copy, Paste

Line-by-Line Explanation:

1. We import [Link].* for GUI components.


2. Create a Frame to display the menu.
3. Create a MenuBar to hold the menus.
4. Add two Menus: "File" and "Edit".
5. Add MenuItems: New, Save, Close to File; Cut, Copy, Paste to Edit.
6. Add both menus to the MenuBar.
7. Attach the MenuBar to the Frame.
8. Set Frame size, layout, and visibility.
9. The main method calls editor() to display the GUI.

Output:
The program creates a window titled AWT Menu with a menu bar containing:
• File Menu → New, Save, Close
• Edit Menu → Cut, Copy, Paste

Conclusion:
This program demonstrates how to create a basic GUI application using Java AWT menus and
menu items.

You might also like