i am getting an error in adding a menu item to a menu

492 views Asked by At
import java.awt.*;

class Menu{
        Frame f;
        MenuBar mb;
        Menu m1,m2,m3;
        MenuItem mn1,mn2,mn3,mn4,mn5,mn6;

        Menu() { 
         f=new Frame();
         mb=new MenuBar();
         m1=new Menu();
         m3=new Menu();
         m2=new Menu();
         mn1=new MenuItem("new");
         mn2=new MenuItem("new");
         mn3=new MenuItem("new");
         mn4=new MenuItem("new");
         mn5=new MenuItem("new");
         mn6=new MenuItem("new");
         m1.add(mn1);
         m1.add(mn2);
         m2.add(mn3);
         m2.add(mn4);
         m3.add(mn5);
         m3.add(mn6);
         mb.add(m1);
         mb.add(m2);
         mb.add(m3);
         f.setMenuBar(mb);
         f.setTitle("menu demo");
         f.setVisible(true);
         f.setSize(300,300);
        }
        public static void main(String[] args){
           new Menu();
        }
    }
3

There are 3 answers

0
Vinay On BEST ANSWER

You have a conflict there with the name Menu. You need to import the proper classes.Use

java.awt.Menu m1=new java.awt.Menu(); 

if you want to go with your class name as Menu or else change your class name to some other name and import a Menu class.

0
johan d On

Hmmm. I think your class name is in conflict with the Menu you'd like to use...

No errors with an other name.

0
Jainendra On

Change the name of your class Menu to some other name, it is conflicting with java.awt.Menu class