Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in Menu, from RHE

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I tried to fit piece of codes from RHE into a java program to let it run, but I always get "wrong argument" message for Menu constructor. No idea what is going on. Can someone help me out?
Thanks a lot.
Chris
import java.awt.*;
public class Menu extends Frame{

public static void main(String args []){
Frame frame;
MenuBar bar;
Menu fileMenu,subMenu,helpMenu;
//Create frame and install menu bar.
frame =new Frame("Menu demo");
frame.setSize(400,300);
bar =new MenuBar();
frame.setMenuBar(bar);
//Create submenu.
subMenu=new Menu("Pull me");
subMenu.add(new MenuItem("Sub-This"));
subMenu.add(new MenuItem("Sub-That"));
//Create and add file menu.
fileMenu =new Menu("File");
fileMenu.add(new MenuItem("New"));
fileMenu.add(new MenuItem("Open"));
fileMenu.addSeparator();
fileMenu.add(new CheckboxMenuItem("Print Preview Mode"));
fileMenu.add(subMenu);
bar.add(fileMenu);
//Create help menu.
helpMenu =new Menu("Help");
helpMenu.add(new MenuItem("Contents ..."));
helpMenu.add(new MenuItem("About this program ..."));
bar.setHelpMenu(helpMenu);
//Now that the frame is completely built,display it
frame.setVisible(true);
}
}
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Chris,
I think your compiler gets confused because your program is called "Menu", which is after all an existing Java class. It compiled just fine after I renamed it.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,
Just change the name of your program to "MenuTest" or something other than Menu. That should do it
Navin
 
Chris Ben
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot.
Chris
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic