I have a generic class which creates a menubar
public class CreateMenuBar { JMenuBar MenuBar; JMenu FileMenu; JMenuItem AddAction; ActionListener MyListener; ServicesFrame ServicesFrame; public JMenuBar CreateMenuBar() { MenuBar = new JMenuBar(); FileMenu = new JMenu("File"); AddAction = new JMenuItem(Add); MenuBar.add(FileMenu); FileMenu.add(AddAction); AddAction.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addService() } }); return MenuBar } public void addService() { //this.setisible(false); // Doesnt work because this is a generic class if (ServicesFrame == null) { ServicesFrame = new ServicesFrame(MenuBar, null); } ServicesFrame.setVisible(true); } }
public class Main { static JMenuBar MainMenuBar; public static void main(String[] args) { CreateMenuBar Menu = new CreateMenuBar(); MainMenuBar = Menu.AddItems(); ListServersFrame ListServersFrame = new ListServersFrame(MainMenuBar); ListServersFrame.setVisible(true); }
public class ListServersFrame extends JFrame implements ActionListener { JMenuBar MainMenuBar; public ListServersFrame(JMenuBar MainMenuBar) { super(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(600, 850); this.setJMenuBar(MainMenuBar);
so i want to click on the menu and switch between frames ( the example above is just one menuitem but i have two which can switch back and forth)
Any ideas? i did try checking if an instance of the frame already exist, if not create one and hide it but i got errors.
Thanks for any ideas
Kurt