/////////////////////////////////////////
/// NATHAN CHAN ///
/// ASSIGNMENT 3 ///
/// INSTRUCTOR: GILBERT TSUI ///
/// COURSE: CSIS 1275 ///
/// SECTION: 01 ///
/// DUE DATE: MARCH 31st 2009 ///
/////////////////////////////////////////
// Please run this program at a 1280 x 1024 resolution.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import java.lang.*;
import java.util.*;
import javax.swing.border.*;
public class MovieBuy extends JApplet implements ActionListener
{
ImageIcon imageClickForMovies = new ImageIcon("clickForMovies1.GIF");
JButton buttonClickForMovies = new JButton(imageClickForMovies);
MovieList movieList = new MovieList();
//String[] data01 = {"Speed Racer", "Star Trek XI", "The Dark Knight", "The X Files 2", "Hulk", "Iron Man", "Made of Honor"};
Vector vtMovieTitles = new Vector();
JList listbox01 = new JList(vtMovieTitles);
//String[] data02 = {"50", "3", "0", "34", "78", "0", "25"};
Vector vtDVDStock = new Vector();
JList listbox02 = new JList(vtDVDStock);
//String[] data03 = {"23", "0", "78", "5", "100", "0", "56"};
Vector vtbluRayStock = new Vector();
JList listbox03 = new JList(vtbluRayStock);
ButtonGroup DVDBluRayGroup = new ButtonGroup();
JRadioButton radDVD = new JRadioButton("DVD", true);
JRadioButton radBluRay = new JRadioButton("blu Ray", false);
String[] copies = {"1 Copy(ies)", "2 Copy(ies)", "3 Copy(ies)", "4 Copy(ies)", "5 Copy(ies)", "6 Copy(ies)", "7 Copy(ies)"};
JComboBox cmbCopies = new JComboBox(copies);
Label label1999 = new Label("$19.99");
Label label3599 = new Label("$39.99");
ImageIcon imageBuy = new ImageIcon("buyLogo1.GIF");
JButton buttonBuy = new JButton(imageBuy);
JList listArea = new JList();
JButton btnClearButton = new JButton("Clear");
JButton btnClearAll = new JButton("Clear All");
Label lblTotal = new Label("Total:");
Label lblEnterCreditCard = new Label("Enter Credit Card#:");
JPasswordField passEnterCreditCard = new JPasswordField();
JButton btnSubmit = new JButton("Submit");
Label lblKeyPadPassword = new Label("Use Keypad to enter password for settings");
JPasswordField passKeyPad = new JPasswordField(10);
JButton buttonA = new JButton("A");
JButton buttonB = new JButton("B");
JButton buttonC = new JButton("C");
JButton buttonD = new JButton("D");
JButton buttonE = new JButton("E");
JButton buttonF = new JButton("F");
JButton buttonG = new JButton("G");
JButton buttonH = new JButton("H");
JButton buttonI = new JButton("I");
JButton buttonJ = new JButton("J");
JButton buttonEnter = new JButton("Enter");
JButton buttonReset = new JButton("Reset");
// Panels
JPanel panel01 = new JPanel(new GridLayout(0,5,8,8));
JPanel panel01a = new JPanel();
JPanel panel01b = new JPanel();
JPanel panel01c = new JPanel();
JPanel panel01d = new JPanel();
JPanel panel01e = new JPanel(new GridLayout(3,0));
JPanel panel01eA = new JPanel(new GridLayout(0,2));
JPanel panel01eB = new JPanel(new GridLayout(0,2));
JPanel panel02 = new JPanel(new FlowLayout());
JPanel panel03 = new JPanel(new GridLayout(0,2,8,8));
JPanel panel03a = new JPanel(new GridLayout(1,0));
JPanel panel03b = new JPanel(new GridLayout(5,0));
JPanel panel03b1 = new JPanel(new GridLayout(0,2));
JPanel panel04 = new JPanel(new FlowLayout());
JPanel panel04a = new JPanel(new GridLayout(4,0));
JPanel panel04a1 = new JPanel();
JPanel panel04a2 = new JPanel(new GridLayout(2,5,3,3));
JPanel panel04a3 = new JPanel(new FlowLayout(FlowLayout.CENTER));
public void init()
{
setLayout(new GridLayout(4,1));
add(panel01);
panel01.add(panel01a);
panel01.add(panel01b);
panel01.add(panel01c);
panel01.add(panel01d);
panel01.add(panel01e);
panel01b.add(listbox01);
panel01c.add(listbox02);
panel01d.add(listbox03);
listbox01.setFixedCellHeight(25);
listbox01.setFixedCellWidth(240);
listbox01.setVisibleRowCount(7);
listbox01.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listbox02.setForeground(Color.gray);
listbox02.setSelectionForeground(Color.gray);
listbox02.setSelectionBackground(Color.green);
listbox02.setFixedCellHeight(25);
listbox02.setFixedCellWidth(240);
listbox02.setVisibleRowCount(7);
listbox02.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listbox03.setForeground(Color.gray);
listbox03.setSelectionForeground(Color.gray);
listbox03.setSelectionBackground(Color.yellow);
listbox03.setFixedCellHeight(25);
listbox03.setFixedCellWidth(240);
listbox03.setVisibleRowCount(7);
listbox03.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
panel01b.setBorder(new TitledBorder("Movie Titles"));
panel01b.setBackground(Color.white);
panel01c.setBorder(new TitledBorder("DVD Stock"));
panel01c.setBackground(Color.white);
panel01d.setBorder(new TitledBorder("blu Ray Stock"));
panel01d.setBackground(Color.white);
add(panel02);
add(panel03);
add(panel04);
buttonClickForMovies.addActionListener(this);
buttonClickForMovies.setPreferredSize(new Dimension(255,225));
panel01a.add(buttonClickForMovies);
panel01e.add(panel01eA);
panel01eA.add(radDVD);
panel01eA.add(label1999);
label1999.setFont(new Font("Arial", Font.BOLD, 12));
label1999.setBackground(Color.green);
panel01e.add(panel01eB);
panel01eB.add(radBluRay);
panel01eB.add(label3599);
DVDBluRayGroup.add(radDVD);
DVDBluRayGroup.add(radBluRay);
label3599.setFont(new Font("Arial", Font.BOLD, 12));
panel01e.add(cmbCopies);
label3599.setBackground(Color.yellow);
buttonBuy.setPreferredSize(new Dimension(315,225));
buttonBuy.addActionListener(this);
panel02.add(buttonBuy,BorderLayout.CENTER);
panel03.add(panel03a);
panel03.add(panel03b);
Border blackline = BorderFactory.createLineBorder(Color.black);
panel03a.setBorder(blackline);
panel03a.add(listArea);
panel03b.add(btnClearButton);
panel03b.add(btnClearAll);
panel03b.add(lblTotal);
lblTotal.setBackground(Color.cyan);
panel03b.add(panel03b1);
lblEnterCreditCard.setAlignment(Label.RIGHT);
lblEnterCreditCard.setFont(new Font("Arial", Font.BOLD, 12));
panel03b1.add(lblEnterCreditCard);
panel03b1.add(passEnterCreditCard);
panel03b.add(btnSubmit);
panel04.add(panel04a);
panel04a.setBackground(Color.red);
panel04a.setBorder(new TitledBorder("For Employee use ONLY"));
panel04a.setBackground(Color.red);
lblKeyPadPassword.setFont(new Font("Arial", Font.BOLD, 12));
panel04a.add(lblKeyPadPassword);
panel04a1.setBackground(Color.red);
panel04a.add(panel04a1);
panel04a1.add(passKeyPad);
panel04a.add(panel04a2);
panel04a2.add(buttonA);
panel04a2.add(buttonB);
panel04a2.add(buttonC);
panel04a2.add(buttonD);
panel04a2.add(buttonE);
panel04a2.add(buttonF);
panel04a2.add(buttonG);
panel04a2.add(buttonH);
panel04a2.add(buttonI);
panel04a2.add(buttonJ);
panel04a.add(panel04a3);
panel04a3.setBackground(Color.red);
panel04a3.add(buttonEnter);
panel04a3.add(buttonReset);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() instanceof JButton)
{
if(e.getSource() == buttonClickForMovies)
movieList.createList();
for(int i = 0; i < movieList.mList.length; i++) // add elements to vtMovieTitles
vtMovieTitles.addElement(movieList.mList[i].getMovieTitle());
listbox01.setListData(vtMovieTitles);
for(int i = 0; i < movieList.mList.length; i++) // add elements to vtDVDStock
vtDVDStock.addElement(movieList.mList[i].getMovieStock('D'));
listbox02.setListData(vtDVDStock);
for(int i = 0; i < movieList.mList.length; i++) // add elements to vtblueRayStock
vtbluRayStock.addElement(movieList.mList[i].getMovieStock('B'));
listbox03.setListData(vtbluRayStock);
}
public void valueChanged(ListSelectionEvent e)
{
// What should I write here? Should I use an index like "i"?
}
}
}