-
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[]){
}
}
-
I agree with the compiler: How can trivia have a method setJMenuBar? I don't see this method defined anywhere in your class?
-
Also, just what is this line of code intended to do?
Quote:
mnuBar.add(mnuBar);
db
-
Or these: Code:
mnuBar.add(mnuFile);
:
:
:
mnuHelpAbout.add(mnuFile);
db
-
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.
-
That's the least of your problems, and a bad solution.
db