Results 1 to 3 of 3
- 03-02-2012, 06:04 PM #1
Senior Member
- Join Date
- Feb 2012
- Posts
- 219
- Rep Power
- 2
Having menu options make a new Panel
I am currently trying to add a GUI to my program. I want to set it up so that the menu buttons bring up a new panel everytime they are invoked.

I am unsure of how to go about doing this however. Here is what I have for the GUI currently
Any help is appreciated. Thank You.Java Code:import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class SchoolSaverGUI implements ActionListener{ public static void main(String[] args) { SchoolSaverGUI s = new SchoolSaverGUI(); } public SchoolSaverGUI() { JFrame frame = new JFrame("School Saver GUI"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("File"); filemenu.add(new JSeparator()); JMenu editmenu = new JMenu("About"); editmenu.add(new JSeparator()); JMenuItem fileItem1 = new JMenuItem("Add Student Record"); JMenuItem fileItem2 = new JMenuItem("Add Course Record"); JMenuItem fileItem3 = new JMenuItem("Add Course"); JMenuItem fileItem4 = new JMenuItem("Print a Student's Schedule"); JMenuItem fileItem5 = new JMenuItem("Print Course Information"); JMenuItem fileItem6 = new JMenuItem("Print School Roster"); JMenuItem fileItem7 = new JMenuItem("Print available Courses"); JMenuItem fileItem8 = new JMenuItem("Exit"); fileItem6.add(new JSeparator()); JMenuItem editItem1 = new JMenuItem("How to use"); JMenuItem editItem2 = new JMenuItem("Information"); filemenu.add(fileItem1); filemenu.add(fileItem2); filemenu.add(fileItem3); filemenu.add(fileItem4); filemenu.add(fileItem5); filemenu.add(fileItem6); filemenu.add(fileItem7); filemenu.add(fileItem8); editmenu.add(editItem1); editmenu.add(editItem2); fileItem1.addActionListener(this); fileItem2.addActionListener(this); fileItem3.addActionListener(this); fileItem4.addActionListener(this); fileItem5.addActionListener(this); fileItem6.addActionListener(this); fileItem7.addActionListener(this); fileItem8.addActionListener(this); editItem1.addActionListener(this); editItem2.addActionListener(this); menubar.add(filemenu); menubar.add(editmenu); frame.setJMenuBar(menubar); frame.setSize(400,400); frame.setVisible(true); } public void test() { } public void actionPerformed(ActionEvent e) { System.out.println("Item clicked: "+e.getActionCommand()); JPanel panel = new JPanel(new GridLayout()); } }
- 03-02-2012, 07:31 PM #2
Senior Member
- Join Date
- Feb 2012
- Posts
- 219
- Rep Power
- 2
Re: Having menu options make a new Panel
-
Re: Having menu options make a new Panel
I think a CardLayout could handle this better and more easily than adding and removing components.
Similar Threads
-
how to make a simple panel??
By stefandanielsen in forum New To JavaReplies: 10Last Post: 05-17-2011, 02:12 PM -
Set Java Control Panel options via Command Prompt
By pguih in forum Advanced JavaReplies: 0Last Post: 05-09-2011, 04:24 PM -
asking user to make choice through menu
By tinaman in forum New To JavaReplies: 6Last Post: 04-23-2011, 08:38 AM -
Menu Options For User
By mnand in forum New To JavaReplies: 1Last Post: 02-02-2009, 03:12 AM -
want to make a menu bar for image processing
By vidhi in forum Java 2DReplies: 1Last Post: 01-15-2008, 07:12 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks