I want to combine as a GUI, a menu, a toolbar and a page which loads files. I have a class called 'MenuBar' with my menu in it, but when i run the code below, I get a runtime error saying that I cannot add a window (presumbaly my menu is a window) to a container. So how do I combine all these different components (i.e. menu's toolbars, windows etc)?
class MainWindow
extends JFrame
implements ActionListener
{
public MainWindow(){
MenuBar menubar = new MenuBar();
JFrame frame = new JFrame("Main Window");
JPanel panel = new JPanel();
frame.setSize(400,400);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.getContentPane().add(menubar);
frame.pack();
frame.show();
}
public void actionPerformed( ActionEvent event )
{
System.out.println( event );
}
public static void main (String args[]){
MainWindow window = new MainWindow();
}
}
class MainWindow
extends JFrame
implements ActionListener
{
public MainWindow(){
MenuBar menubar = new MenuBar();
JFrame frame = new JFrame("Main Window");
JPanel panel = new JPanel();
frame.setSize(400,400);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.getContentPane().add(menubar);
frame.pack();
frame.show();
}
public void actionPerformed( ActionEvent event )
{
System.out.println( event );
}
public static void main (String args[]){
MainWindow window = new MainWindow();
}
}