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{
'About' should be a JMenuItem
, not a JMenu
. Try this...
about = new JMenuItem("About");