0

I am trying to develop java menubar with different items on it. And once you click on the selected item another window should be opened. I manage to run the menu but it seems I can not open the other windows. In other words my menu item is there but for one or another reason is not working. Can you see on my code bellow where am I making the mistake?

    package cbrrecommender.main;

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

public class GUI extends JFrame {

    JMenuBar menubar;
    JMenu help;
    JMenuItem about;

    public GUI() {
        setLayout(new FlowLayout());

        menubar = new JMenuBar();
        add(menubar);

        help = new JMenu("Help");
        menubar.add(help);

        about = new JMenu("About");
        help.add(about);

        setJMenuBar(menubar);

        event e = new event();
        about.addActionListener(e);
    }

    public class event implements ActionListener {
        public void actionPerformed(ActionEvent e) {

            FullGUI gui = new FullGUI(GUI.this);
            gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
            gui.setSize(300, 100);
            gui.setLocation(300, 300);
            gui.setVisible(true);

        }
    }

    public static void main(String args[]) {
        GUI gui = new GUI();
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setSize(300, 100);
        gui.setVisible(true);
        gui.setTitle("Main Window");
    }


}

The piece of code where I am extending the other class FullGUI is :

public class FullGUI  extends GUI{
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
John
  • 627
  • 6
  • 19

1 Answers1

1

'About' should be a JMenuItem, not a JMenu. Try this...

about = new JMenuItem("About");
Zutty
  • 5,357
  • 26
  • 31
  • Thanks to your advise I manage to run the GUI however when I load the screen an empty dialog gui is appearing in front of the other GUI do you know where it might come from. PS: Check my edited code up pls. – John Jan 14 '13 at 10:23
  • It depends on what is in the `FullGUI` class. – Zutty Jan 14 '13 at 14:05