import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
public class MainFramePanel extends JPanel {
JButton ExitSystem, InventoryDepartment, AccountingDepartment, Invoices;
JLabel title;
public MainFramePanel() {
//create panel for title
//setLayout(new BorderLayout());
//JPanel primary = new JPanel();
//add (primary, BorderLayout.NORTH);
//create panel to hold four main buttons
JPanel buttonHolder = new JPanel();
buttonHolder.setLayout (new BoxLayout (buttonHolder, BoxLayout.Y_AXIS));
buttonHolder.setForeground(new Color(240, 250, 240));
buttonHolder.setBackground(new Color(46, 139, 87));
buttonHolder.setPreferredSize(new Dimension(300,300));
add(buttonHolder, BorderLayout.SOUTH);
//create a panel to hold the title
setLayout(new BorderLayout());
JPanel titleHolder = new JPanel();
titleHolder.setBackground(new Color(46, 139, 87));
titleHolder.setForeground(new Color(240, 250, 240));
titleHolder.setPreferredSize(new Dimension(300,300));
add(titleHolder, BorderLayout.NORTH);
//create the title itself
title = new JLabel("Warehouse Inventory System");
title.setPreferredSize (new Dimension(600,100));
title.setForeground(new Color(46, 139, 87);
title.setBackground(new Color(240, 250, 240);
Font font = new Font("Bradley Hand ITC", Font.PLAIN, 45);
title.setFont(font);
add(title, BorderLayout.NORTH);
//add buttons to the main page and color them correctly to match main page
ExitSystem = new JButton("Exit System");
ExitSystem.setForeground(new Color(46, 139, 87));
ExitSystem.setBackground(new Color(240, 250, 240));
ExitSystem.setAlignmentX(Component.CENTER_ALIGNMENT);
Font font1 = new Font("Bradley Hand ITC", Font.PLAIN, 30);
ExitSystem.setFont(font1);
ExitSystem.setMaximumSize(new Dimension(400, 100));
InventoryDepartment = new JButton("Inventory Department");
InventoryDepartment.setForeground(new Color(46, 139, 87));
InventoryDepartment.setBackground(new Color(240, 250, 240));
InventoryDepartment.setAlignmentX(Component.CENTER_ALIGNMENT);
InventoryDepartment.setFont(font1);
InventoryDepartment.setMaximumSize(new Dimension(400, 100));
AccountingDepartment = new JButton("Accounting Department");
AccountingDepartment.setForeground(new Color(46, 139, 87));
AccountingDepartment.setBackground(new Color(240, 250, 240));
AccountingDepartment.setAlignmentX(Component.CENTER_ALIGNMENT);
AccountingDepartment.setFont(font1);
AccountingDepartment.setMaximumSize(new Dimension(400, 100));
Invoices = new JButton("Invoices");
Invoices.setForeground(new Color(46, 139, 87));
Invoices.setBackground(new Color(240, 250, 240));
Invoices.setAlignmentX(Component.CENTER_ALIGNMENT);
Invoices.setFont(font1);
Invoices.setMaximumSize(new Dimension(400, 100));
//add buttons to the display
buttonHolder.add(Box.createHorizontalStrut(10));
buttonHolder.add(ExitSystem);
buttonHolder.add(Box.createHorizontalStrut(10));
buttonHolder.add(InventoryDepartment);
buttonHolder.add(Box.createHorizontalStrut(10));
buttonHolder.add(AccountingDepartment);
buttonHolder.add(Box.createHorizontalStrut(10));
buttonHolder.add(Invoices);
buttonHolder.add(Box.createHorizontalStrut(10));
//add display panel to main page
add(buttonHolder, BorderLayout.CENTER);
//add listeners
ButtonListener listener = new ButtonListener();
ExitSystem.addActionListener(listener);
InventoryDepartment.addActionListener(listener);
AccountingDepartment.addActionListener(listener);
Invoices.addActionListener(listener);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == ExitSystem)
title.setText("Exit Pushed");
if(event.getSource() == InventoryDepartment)
title.setText("Inventory Hit");
if(event.getSource() == AccountingDepartment)
title.setText("Accounting Hit");
if(event.getSource() == Invoices)
title.setText("Invoices Hit");
}
}
}
This is main in case you need it...
import javax.swing.*;
public class WarehouseInventorySystem {
public static void main(String[] args) {
//Displaying the main page GUI
JFrame frame = new JFrame ("Main Page");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new MainFramePanel());
frame.pack();
frame.setVisible(true);
}
}

New Topic/Question
Reply




MultiQuote




|