Hello,
I'm trying to add a JMenuBar to a JFrame and having alot of difficulties with it. I've searched the net and gone through a book I have looking for a solution to the problem, but everywhere tells me I'm doing it right, yet I've no JMenuBar at the top of my program.
If anyone can see what I'm doing wrong it would be greatly appreciated. I'm a bit stumped at the moment. I've just included the first Class and Method as the rest is very long and doesn't relate to the problem.
Thanks,
Crisko
class MainWindow extends JFrame implements ActionListener {
JFrame window = new JFrame();
JPanel slider = new JPanel(new GridLayout(3, 4, 3, 3));
JMenuBar topMenu = new JMenuBar();
JMenu gameMenu = new JMenu();
JMenu soundMenu = new JMenu();
JMenu helpMenu = new JMenu();
JMenuItem restartItem = new JMenuItem("Restart Game", KeyEvent.VK_T);
JRadioButtonMenuItem rbsoundonItem = new JRadioButtonMenuItem("Sound On");
JRadioButtonMenuItem rbsoundoffItem = new JRadioButtonMenuItem("Sound Off");
ButtonGroup sounds = new ButtonGroup();
JMenuItem helpItem = new JMenuItem("Help", KeyEvent.VK_T);
JMenuItem aboutItem = new JMenuItem("About", KeyEvent.VK_T);
JButton one = new JButton("1");
JButton two = new JButton("2");
JButton three = new JButton("3");
JButton four = new JButton("4");
JButton five = new JButton("5");
JButton six = new JButton("6");
JButton seven = new JButton("7");
JButton eight = new JButton("8");
JButton blank = new JButton();
public MainWindow() {
super("Ciaran's Slider Game, Yo");
window.setSize(300,300);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
one.addActionListener(this);
two.addActionListener(this);
three.addActionListener(this);
four.addActionListener(this);
five.addActionListener(this);
six.addActionListener(this);
seven.addActionListener(this);
eight.addActionListener(this);
slider.add(one);
slider.add(two);
slider.add(three);
slider.add(four);
slider.add(five);
slider.add(six);
slider.add(seven);
slider.add(eight);
slider.add(blank);
helpMenu.add(helpItem);
helpItem.addActionListener(this);
helpMenu.add(aboutItem);
aboutItem.addActionListener(this);
rbsoundonItem.setSelected(true);
rbsoundonItem.addActionListener(this);
rbsoundoffItem.addActionListener(this);
sounds.add(rbsoundoffItem);
sounds.add(rbsoundonItem);
soundMenu.add(rbsoundonItem);
soundMenu.add(rbsoundoffItem);
restartItem.addActionListener(this);
gameMenu.add(restartItem);
topMenu.add(gameMenu);
topMenu.add(soundMenu);
topMenu.add(helpMenu);
window.getContentPane().add(topMenu);
window.setJMenuBar(topMenu);
window.getContentPane().add(slider);
window.setVisible(true);
}