-
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
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]
-
Could you please put corect tags.
-
-
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.
-
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