1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

Yet more Java assistance, please.

Discussion in 'BBS Hangout' started by GladiatoRowdy, Nov 15, 2007.

  1. GladiatoRowdy

    GladiatoRowdy Member

    Joined:
    Oct 15, 2002
    Messages:
    16,596
    Likes Received:
    496
    I only get one compilation error on the line where I declare the private Menu variables. JCreator reports "cannot access Menu" and stops. I can't eve find that error message on Google except as it has to do with hacking the software on cell phones. :eek:

    Code:
    /*
    File Name: Menu.java
    Assignment 5
    COSC 3134
    Andy Moon
    */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    class HouseholdInformationMenu extends Frame implements ActionListener
    {
    	private MenuBar bar;
    	private Menu systemMenu, householdMenu, processMenu;
    	private MenuItem loadData, exit, inquireInfo, processPoverty;
    	
    	public HouseholdInformationMenu()
    	{
    		super("Household Information System");
    		setSize(200,100);
    		
    		//Create Menu Bar
    		bar=new MenuBar();
    		
    		//Create System menu
    		systemMenu = new Menu("System");
    		
    		//Create Household Information menu
    		householdMenu = new Menu("Household Information");
    		
    		//Create Process menu
    		processMenu = new Menu("Process");
    		
    		//Create System menu items
    		loadData = new MenuItem("Load Household Data");
    		loadData.addActionListener(this);
    		systemMenu.add(loadData);
    		exit = new MenuItem("Exit");
    		exit.addActionListener(this);
    		systemMenu.add(exit);
    		
    		//Create Household Information menu item
    		inquireInfo = new MenuItem("Inquire Household Information");
    		inquireInfo.addActionListener(this);
    		householdMenu.add(inquireInfo);
    		
    		//Create Process menu item
    		processPoverty = new MenuItem("Process Poverty Information");
    		processPoverty.addActionListener(this);
    		householdMenu.add(processPoverty);
    		
    		bar.add(systemMenu);
    		bar.add(householdMenu);
    		bar.add(processMenu);
    		
    		setMenuBar(bar);
    		
    		setVisible(true);
    	}
    }
     
    #1 GladiatoRowdy, Nov 15, 2007
    Last edited: Nov 15, 2007
  2. GladiatoRowdy

    GladiatoRowdy Member

    Joined:
    Oct 15, 2002
    Messages:
    16,596
    Likes Received:
    496
    Renewing the request!
     
  3. SwoLy-D

    SwoLy-D Member

    Joined:
    Jul 20, 2001
    Messages:
    37,618
    Likes Received:
    1,456
    Can you still edit that post above? If so, use the
    Code:
     tags, please... you forgot :D. 
    
    Should you really do the * when importing?? Isn't that dangerous? :eek:
     
  4. GladiatoRowdy

    GladiatoRowdy Member

    Joined:
    Oct 15, 2002
    Messages:
    16,596
    Likes Received:
    496
     
  5. rockmanslim

    rockmanslim Member

    Joined:
    Nov 28, 2002
    Messages:
    1,404
    Likes Received:
    14
    Assuming the filename is Menu.java, the filename does not match the class name.

    Either change the filename from Menu.java to HouseholdInformationMenu.java,

    or change the name of the class (and its constructor) to Menu.


    Also, since you are implementing ActionListener, the class needs to have a concrete implementation of the method actionPerformed( ActionEvent evt ).
     
  6. rockmanslim

    rockmanslim Member

    Joined:
    Nov 28, 2002
    Messages:
    1,404
    Likes Received:
    14
    Actually, the part above is a pretty bad idea since Menu is a pre-existing Java class. You could rename the class to Menu, but then you'd have to fully qualify the class name (Menu) every time you mean the existing Java class and not the class you are currently defining.

    For example, every place you see "Menu" (except for the class name and the constructor name), you'd instead have to say "java.awt.Menu".

    To avoid all that, just change the file name to match the class name you have (Householdxxxxx...) .
     

Share This Page