0% found this document useful (0 votes)
20 views3 pages

Document

JC fact f hindi

Uploaded by

saurabh sudake
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)
20 views3 pages

Document

JC fact f hindi

Uploaded by

saurabh sudake
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
You are on page 1/ 3

5 Write a java program using AWT to create a menubar where the menubar contains

menu items such as file edit view and create a submenu

Import java.awt.*;

Import java.awt.event.*;

Public class MenuBarExample {

Public static void main(String[] args) {

Frame frame = new Frame(“Menu Bar Example”);

// Create a menu bar

MenuBar menuBar = new MenuBar();

// Create menus

Menu fileMenu = new Menu(“File”);

Menu editMenu = new Menu(“Edit”);

Menu viewMenu = new Menu(“View”);

// Create menu items

MenuItem newItem = new MenuItem(“New”);

MenuItem openItem = new MenuItem(“Open”);

MenuItem saveItem = new MenuItem(“Save”);

MenuItem exitItem = new MenuItem(“Exit”);

// Add menu items to the File menu

fileMenu.add(newItem);

fileMenu.add(openItem);

fileMenu.add(saveItem);
fileMenu.addSeparator(); // Add a separator line

fileMenu.add(exitItem);

// Create a submenu

Menu subMenu = new Menu(“Submenu”);

MenuItem subItem1 = new MenuItem(“Sub Item 1”);

MenuItem subItem2 = new MenuItem(“Sub Item 2”);

subMenu.add(subItem1);

subMenu.add(subItem2);

// Add the submenu to the File menu

fileMenu.add(subMenu);

// Add menus to the menu bar

menuBar.add(fileMenu);

menuBar.add(editMenu);

menuBar.add(viewMenu);

// Set the menu bar for the frame

Frame.setMenuBar(menuBar);

// Set frame properties

Frame.setSize(400, 400);

Frame.setLayout(null);

Frame.setVisible(true);

// Add window listener to close the window

Frame.addWindowListener(new WindowAdapter() {
Public void windowClosing(WindowEvent we) {

System.exit(0);

});

You might also like