Results 1 to 3 of 3
  1. #1
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default 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.

    Having menu options make a new Panel-gui.jpg


    I am unsure of how to go about doing this however. Here is what I have for the GUI currently

    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()); 
    	      
    	   }
    }
    Any help is appreciated. Thank You.

  2. #2
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: Having menu options make a new Panel

    I made some progress. I have two panels, one is displayed by default. When I click on "Add Course Record", it removes the first panel and replaces it with the first panel.

    Having menu options make a new Panel-untitled.png

    Having menu options make a new Panel-giu.png


    Am I headed in the right direction, or is this going to encounter problems in the future?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. how to make a simple panel??
    By stefandanielsen in forum New To Java
    Replies: 10
    Last Post: 05-17-2011, 03:12 PM
  2. Set Java Control Panel options via Command Prompt
    By pguih in forum Advanced Java
    Replies: 0
    Last Post: 05-09-2011, 05:24 PM
  3. asking user to make choice through menu
    By tinaman in forum New To Java
    Replies: 6
    Last Post: 04-23-2011, 09:38 AM
  4. Menu Options For User
    By mnand in forum New To Java
    Replies: 1
    Last Post: 02-02-2009, 04:12 AM
  5. Replies: 1
    Last Post: 01-15-2008, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •