Results 1 to 6 of 6
  1. #1
    loley1000 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default setJMenuBar error

    this is my program so far...i know that it doesn't show anything yet, obviously...It's supposed to be a trivia game. I haven't gotten to far yet because i keep getting an error with setJMenuBar(mnuBar);
    It saying "The method 'setJMenuBar(mnuBar) is undefined for type trivia" and i don't know why. I'm using Eclipse IDE Helios.



    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JMenuBar;


    public class trivia implements ActionListener {

    JButton simpsons = new JButton();
    JButton sienfeld = new JButton();
    JButton topGear = new JButton();

    String[] simponsQuestions = {"Homer was mad about recieving this football team as a gift because it wasn't the Dallas Cowboys.","Homer drove this man to killing himself.",
    "Ralph ate this color berry, that were poisonous, in the Simpsons rip-off of Lord of the Flies","What is the street address of the simpsons", "What were Lisa's first words?",
    "Homer constantly 'borrows' things from which neighbor", "Why has Homer's mother been absent for so long", "What is Homers middle name?",
    "A Real life version of the simpsons house was actually built, what state is it in?", "The Simpsons started out as a short on what other show?"};
    String[] sienfeldQuestions = {};
    String[] topQuestions = {"What is James May's nickname?", "What car was Richard Hammond driving when he proclaimed 'I AM A DRIVING GOD!' ?",};

    public trivia(){
    super();
    }

    public JMenuBar createMenuBar(){
    JMenuBar mnuBar = new JMenuBar();
    setJMenuBar(mnuBar);

    JMenu mnuFile = new JMenu("File", true);
    mnuFile.setMnemonic(KeyEvent.VK_F);
    mnuFile.setDisplayedMnemonicIndex(0);
    mnuBar.add(mnuFile);

    JMenuItem mnuFileExit = new JMenu("Exit", true);
    mnuFile.setMnemonic(KeyEvent.VK_X);
    mnuFile.setDisplayedMnemonicIndex(1);
    mnuFileExit.add(mnuFile);
    mnuFileExit.setActionCommand("Exit");
    mnuFileExit.addActionListener(this);

    JMenu mnuEdit = new JMenu("Edit", true);
    mnuEdit.setMnemonic(KeyEvent.VK_E);
    mnuEdit.setDisplayedMnemonicIndex(0);
    mnuBar.add(mnuFile);

    JMenuItem mnuEditRestart = new JMenu("Restart", true);
    mnuFile.setMnemonic(KeyEvent.VK_R);
    mnuFile.setDisplayedMnemonicIndex(1);
    mnuFileExit.add(mnuFile);
    mnuFileExit.setActionCommand("Restart");
    mnuFileExit.addActionListener(this);

    JMenu mnuHelp = new JMenu("Help", true);
    mnuHelp.setMnemonic(KeyEvent.VK_H);
    mnuHelp.setDisplayedMnemonicIndex(0);
    mnuBar.add(mnuBar);

    JMenuItem mnuHelpAbout = new JMenu("About", true);
    mnuHelp.setMnemonic(KeyEvent.VK_A);
    mnuHelp.setDisplayedMnemonicIndex(0);
    mnuHelpAbout.add(mnuFile);
    mnuHelpAbout.setActionCommand("About");
    mnuHelpAbout.addActionListener(this);

    return mnuBar;
    }



    public Container createConentPane (){

    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new FlowLayout());
    centerPanel.add(simpsons);
    centerPanel.add(sienfeld);
    centerPanel.add(topGear);
    topGear.setLocation(150, 220);
    simpsons.setLocation(350, 220);
    sienfeld.setLocation(500, 220);

    Container c = new Container();
    c.setLayout(new BorderLayout(10,10));
    c.add(centerPanel, BorderLayout.CENTER);

    return c;
    }



    public static void main (String args[]){


    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I agree with the compiler: How can trivia have a method setJMenuBar? I don't see this method defined anywhere in your class?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    Also, just what is this line of code intended to do?
    mnuBar.add(mnuBar);
    db

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    Or these:
    Java Code:
    mnuBar.add(mnuFile);
    :
    :
    :
    mnuHelpAbout.add(mnuFile);
    db

  5. #5
    loley1000 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    i figured out my proble, i needed to add "extends JFrame" to my class. I don't need to define setJMenuBar() it's inherited with the javax.swing import.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •