0% found this document useful (0 votes)
3K views3 pages

Practical No 5 AJP

The document discusses two programs related to creating menus in Java using AWT. The first program creates a menu with different color options and disables the "Black" option. The second program contains an error where it is trying to add a MenuShortcut to a MenuItem without using the appropriate constructor. The exercise is to find the error in the second program.

Uploaded by

nstrnsdtn
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)
3K views3 pages

Practical No 5 AJP

The document discusses two programs related to creating menus in Java using AWT. The first program creates a menu with different color options and disables the "Black" option. The second program contains an error where it is trying to add a MenuShortcut to a MenuItem without using the appropriate constructor. The exercise is to find the error in the second program.

Uploaded by

nstrnsdtn
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

Name: Ranvir Avinash Bitthalrao Roll No.

: 60

Name: Ranvir Avinash Vitthalrao Sub.: AJP


Roll NO.: 60 Enrollment: 2000690184

Practical No. 5: Write a program using AWT to create a menu bar where menu
bar contains menu items such as File, Edit, View and create a submenu under
the File menu: New and Open.

➢ Program Code:
1. Write a program which creates Menu of different colors and disable
menu item for Black color.
Code:
import java.awt.*;

class MenuExam2 extends Frame


{

public static void main(String[] args)


{
Frame fr = new Frame("Menu Items");
MenuBar menuBar;
Menu menu1;
MenuItem mItem1, mItem2, mItem3, mItem4, mItem5, mItem6;

menuBar= new MenuBar();


menu1 = new Menu("Colors");
mItem1 = new Menu("White");
mItem2 = new MenuItem("Green");
mItem3 = new MenuItem("Yellow");
mItem4 = new MenuItem("Black");
mItem5 = new MenuItem("Blue");
mItem6 = new MenuItem("Purple");

menu1.add(mItem1);
menu1.add(mItem2);
menu1.add(mItem3);
menu1.add(mItem4);
menu1.add(mItem5);
menu1.add(mItem6);
Name: Ranvir Avinash Bitthalrao Roll No.: 60

mItem4.setEnabled(false);
menuBar.add(menu1);
fr.setMenuBar(menuBar);
fr.setSize(330,250);
fr.setVisible(true);
}
}

Output:
Name: Ranvir Avinash Bitthalrao Roll No.: 60

➢ Exercise:
1. Find error in following program and display output as shown below.
Code:
import java.awt.*;
import java.awt.event.*;
public class MenuDemo1 extends Frame{
MenuBar mb;
MenuItem m1,m2,m3,m4;
Menu mn;
MenuShortcut ms;
MenuDemo1(){
setTitle("MenuBar Demo");
setSize(500,500);
setLayout(null);
ms=new MenuShortcut(KeyEvent.VK_X);
mn=new Menu("File");
mb=new MenuBar();
setMenuBar(mb);
m1=new MenuItem("New..");
m2=new MenuItem("Open");
m3=new MenuItem("Save As..");
m4=new MenuItem("Exit",ms);
mn.add(m1);
mn.add(m2);
mn.add(m3);
mn.addSeparator();
mn.add(m4);
mb.add(mn);
}
public static void main(String args[]){
MenuDemo1 md = new MenuDemo1();
md.setVisible(true);
}}

Output:

You might also like