package inventory;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CDs extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L; // serial version
// declares var for currentIndex for button functionality
public int currentIndex = 0;
// creates cars for the GUI build
private JLabel labelName;
private JLabel labelID;
private JLabel labelStock;
private JLabel labelGenre;
private JLabel labelPrice;
private JLabel labelReStock;
private JLabel labelFval;
private JLabel labelTval;
public CDs(){// sets the GUI
//creates the panel and title fields
JPanel panel = new JPanel();
panel.setLayout(null);
/// fields numbered 1-8 for easy matching with other functions and adding
labelName = new JLabel ("CD Name: ");//1
labelName.setFont(new Font("Serif", Font.BOLD, 14));
labelName.setBounds(0, 0, 200, 50);
labelID = new JLabel ("CD ID: ");//2
labelID.setFont(new Font("Serif", Font.BOLD, 14));
labelID.setBounds(0, 0, 200, 100);
labelGenre = new JLabel ("CD genre: ");//3
labelGenre.setFont(new Font("Serif", Font.BOLD, 14));
labelGenre.setBounds(0, 0, 200, 150);
labelStock = new JLabel ("Stock amount: ");//4
labelStock.setFont(new Font("Serif", Font.BOLD, 14));
labelStock.setBounds(0, 0, 200, 200);
labelPrice = new JLabel ("CD Price: ");//5
labelPrice.setFont(new Font("Serif", Font.BOLD, 14));
labelPrice.setBounds(0, 0, 200, 250);
labelReStock = new JLabel ("ReStock value: ");//6
labelReStock.setFont(new Font("Serif", Font.BOLD, 14));
labelReStock.setBounds(0, 0, 200, 300);
labelFval = new JLabel ("CD stock value: ");//7
labelFval.setFont(new Font("Serif", Font.BOLD, 14));
labelFval.setBounds(0, 0, 200, 350);
labelTval = new JLabel ("Total inventory value: ");//8
labelTval.setFont(new Font("Serif", Font.BOLD, 14));
labelTval.setBounds(125, 0, 200, 500);
// adds the fields
panel.add(labelName);//1
panel.add(labelID);//2
panel.add(labelGenre);//3
panel.add(labelStock);//4
panel.add(labelPrice);//5
panel.add(labelReStock);//6
panel.add(labelFval);//7
panel.add(labelTval);//8
getContentPane().add(panel);
/// creates the buttons
JButton previous = new JButton("Previous");
previous.setBounds(110, 300, 85, 20);
panel.add(previous);
JButton next = new JButton("Next");
next.setBounds(230, 300, 85, 20);
panel.add(next);
// sets the values for the window
setTitle("Your Inventory Program");
setSize(500,550);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
///// these are the active listeners for the button functions
previous.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showPrevious();
}
});
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showNext();
}
});
updateGUI(); /// calls the GUI display for object results
}// sets GUI
public static void main(String[] args){ // start main
Inventory[] CD = new Inventory[5]; // creates the variable CD for the array
/// CD inventory objects
CD[0] = new InvMore("Red Hot Chili Peppers", "Alternative", 1188, 25, 16.99);
CD[1] = new InvMore("Nirvana", "Classic Rock", 1177, 35, 16.99);
CD[2] = new InvMore("Styx", "Classic Rock", 1166, 31, 16.99);
CD[3] = new InvMore("Jay Z", "Hip Hop/Rap", 1155, 45, 16.99);
CD[4] = new InvMore("Nelly", "Hip Hop/Rap", 1144, 35, 16.99);
new CDs(CD).setVisible(true); // this should call the GUI
}// end main
// calls and prints the objects by specifics
public void updateGUI() {
InvMore item = CDs.get(currentIndex);
labelName.setText(String.valueOf(item.getName()));//1
labelID.setText(String.valueOf(item.getID()));//2
labelGenre.setText(String.valueOf(item.getGenre()));//3
labelStock.setText(String.valueOf(item.getStock()));//4
labelPrice.setText(String.format("$%.2f",item.getPrice()));//5
labelReStock.setText(String.format("$%.2f",item.getReStock()));//6
labelFval.setText(String.format("$%.2f",item.getcdVal()));//7
labelTval.setText(String.format("$%.2f",item.getcdVal()));//8
}// ends updateGUI
private void showNext() { // method for the next button
if (currentIndex < 4 - 1) {
currentIndex++;
updateGUI();
}
}
private void showPrevious() { // method for the previous button
if (currentIndex > 0) {
currentIndex--;
updateGUI();
}
}
}// end class