Results 1 to 5 of 5
  1. #1
    abetemari is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default CardLayout manager

    I am stuck here people. How can I use the cardLayout manager to display different panels on the same frame depending on a menu selection? SOS

    Java Code:
    [PHP]class BookStoreFrame extends JFrame
    {
        public BookStoreFrame()
        {
            
            setTitle("XX Book Store");
            setPreferredSize(new Dimension(800, 400));
            setResizable(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.add(new WelcomePanel());
            this.pack();
            centerWindow(this);
            
            JMenuBar menuBar = new JMenuBar();
    
            // Add the menubar to the frame
            setJMenuBar(menuBar);
    
            //JMenuBar menuBar = new JMenuBar();
            JMenu saleMenu = new JMenu("Sales");
            JMenu returnMenu = new JMenu("Returns");
            JMenu inventoryMenu = new JMenu("Inventory");
            JMenu printMenu = new JMenu("Print");
            menuBar.add(saleMenu);
            menuBar.add(returnMenu);
            menuBar.add(inventoryMenu);
            menuBar.add(printMenu);
            // Create and add simple menu item to one of the drop down menu
            JMenuItem saleAction = new JMenuItem("Make sales");
            JMenuItem returnAction = new JMenuItem("Process Returns");
            JMenuItem addNewBookAction = new JMenuItem("Add New Book");
            JMenuItem checkInventoryAction = new JMenuItem("Availability");
            JMenuItem printDailyAction = new JMenuItem("Print Daily Report");
            
    
            saleMenu.add(saleAction);
            returnMenu.add(returnAction);
            inventoryMenu.add(addNewBookAction);
            inventoryMenu.add(checkInventoryAction);
            printMenu.add(printDailyAction);
            
        
            saleAction.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent arg0)
                {
                    //salesPanel
               }
            });
    
             returnAction.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent arg0)
                {
                    //returnPanel
                }
            });
             
            addNewBookAction.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent arg0)
                {
                    //inventoryPanel
                }
            });  
            
            checkInventoryAction.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent arg0)
                {
                    //inventoryPanel
                }
            });  
            printDailyAction.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent arg0)
                {
                    //printPanel
                }
            });  
            
      }
    [/PHP]

  2. #2
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    Could you please put corect tags.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

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

    Default

    How is this different from the thread that you already have active on this question? Which thread should we address answers to? Please let's prevent needless splitting of a discussion.

  5. #5
    abetemari is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default

    They are the same but the change in title of the post , I thought, would more appropriately describe the topic. Sorry for any confusion/unnecessary duplication

Similar Threads

  1. Using a FlowLayout on top of a CardLayout
    By snieuw in forum New To Java
    Replies: 1
    Last Post: 11-08-2010, 06:03 PM
  2. Help with CardLayout
    By Kyle227 in forum New To Java
    Replies: 4
    Last Post: 05-28-2010, 01:03 AM
  3. cardlayout question
    By newbie123 in forum New To Java
    Replies: 1
    Last Post: 04-05-2010, 11:53 PM
  4. Regarding CardLayout
    By adeeb in forum AWT / Swing
    Replies: 1
    Last Post: 06-07-2008, 07:52 PM
  5. Using previous with CardLayout
    By uncopywritable in forum New To Java
    Replies: 2
    Last Post: 08-05-2007, 09:43 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
  •