Java - Pets Inventory 2 (GUI)

Maintain an inventory of pets using a GUI.

MVC

Model, View and Controller -- a concept that common in most programming languages. In the first Pets Inventory assignment, I've already created the Model and Controller. Now to add in the View which is the GUI.

View

package mvc;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.WindowEvent;
import javax.swing.DefaultListModel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;


class View extends JFrame{
    JPanel panelTitle, buttonPanel, leftPanel, rightPanel, bottomPanel;
    public JTextArea textarea;
    JList list;
    JTextField textfield;
    JButton addButton, sellButton, setButton, getButton, listButton;

    DefaultListModel<String> listModel = new DefaultListModel<>();

    public View(String title) throws HeadlessException{
        super(title);
        setVisible(true);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        textfield = new JTextField();        

        panelTitle = new JPanel(new FlowLayout(FlowLayout.CENTER));
        panelTitle.add(new JLabel("Pet Shop"));
        panelTitle.setPreferredSize(new Dimension(200,28));
        panelTitle.setBackground(Color.decode("#D4E2EF"));
        add(panelTitle,BorderLayout.NORTH);        

        textarea = new JTextArea();
        textarea.setForeground(Color.BLACK);
        textarea.setBackground(Color.decode("#FFFFFF"));
        textarea.setText("Welcome to the PetShop!\n");
        JScrollPane scrollTextArea = new JScrollPane(textarea);
        scrollTextArea.setPreferredSize(new Dimension(498,200));
        add(scrollTextArea, BorderLayout.CENTER);

        list = new JList();
        list.setModel(listModel);
        JScrollPane scrollpane = new JScrollPane(list);
        scrollpane.setPreferredSize(new Dimension(200,200));

        leftPanel = new JPanel();
        leftPanel.setBackground(Color.decode("#FFFFFF"));
        leftPanel.setPreferredSize(new Dimension(2,400));

        rightPanel = new JPanel();
        rightPanel.setBackground(Color.decode("#FFFFFF"));
        rightPanel.setPreferredSize(new Dimension(200,400));

        add(leftPanel, BorderLayout.WEST);
        add(scrollpane, BorderLayout.EAST);        

        bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
        bottomPanel.setBackground(Color.decode("#D4E2EF"));
        add(bottomPanel,BorderLayout.SOUTH);
        bottomPanel.setPreferredSize(new Dimension(600,40));

        //add buttons
        bottomPanel.add(new JLabel("Petname: "));
        textfield = (JTextField)bottomPanel.add(new JTextField(15));
        textfield.requestFocus();
        addButton = (JButton)bottomPanel.add(new JButton("Add"));
        sellButton = (JButton)bottomPanel.add(new JButton("Sell"));
        setButton = (JButton)bottomPanel.add(new JButton("Set"));
        getButton = (JButton)bottomPanel.add(new JButton("Get"));
        listButton = (JButton)bottomPanel.add(new JButton("List"));

        pack();
    }

    public JButton getAddButton(){
        return addButton;
    }
    public JButton getSellButton(){
        return sellButton;
    }

    public JButton getSetButton(){
        return setButton;
    }

    public JButton getGetButton(){
        return getButton;
    }

    public JButton getListButton(){
        return listButton;
    }

}

Main

This brings together and calls upon the MVC quite nicely.

package mvc;

public class MVC{
    public static void main(String[] args){
        Model model = new Model();
        model.inventory.loadPets();
        View view = new View("Pet Shop - Assignment 2");
        Controller controller = new Controller(model, view);
    }
}

Pictures of the View

When List button is clicked. Pet List

When Get, Sell, Add, and Set is clicked. Pet List