I am trying to add 5 buttons to work. What am I missing?
CODE
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//a liitle GUI
class GUI1 extends JFrame {
protected double currentItems;
private JTextField jtfVideo; //1
private JTextField jtfRating; //2
private JTextField jtfitmNumber; //3
private JTextField jtfStock;//4
private JTextField jtfReStock; //5 getrestock()
private JTextField jtfPrice; //6
private JTextField jtfValue; //7 getresult()
private JTextField jtftotalInv;//8
private JButton btnIcon; //JLabel icon
private JButton btnFirst;
private JButton btnPrevious;
private JButton btnNext;
private JButton btnLast;
// movies to display
DVD[] dvd;
// index of the movie to display
int index = 0;
GUI1(){
super("Inventory Part of DVD Movies");
//this.inventory1 = inventory1;
JButton btn;
JPanel jp;
JLabel jl;
JPanel outerPanel = new JPanel();
outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
jl = new JLabel("Inventory Part 4");
titlePanel.add(jl);
outerPanel.add(titlePanel);
JPanel numberPanel = new JPanel();
numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Video: " );
numberPanel.add(jl);
jtfVideo = new JTextField (21);
jtfVideo.setEditable(false);
numberPanel.add(jtfVideo);
outerPanel.add(numberPanel);
JPanel number1Panel = new JPanel();
number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Rating: " );
number1Panel.add(jl);
jtfRating = new JTextField(21);
jtfRating.setEditable(false);
number1Panel.add(jtfRating);
outerPanel.add(number1Panel);
JPanel number2Panel = new JPanel();
number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Item Number: ");
number2Panel.add(jl);
jtfitmNumber = new JTextField(21);
jtfitmNumber.setEditable(false);
number2Panel.add(jtfitmNumber);
outerPanel.add(number2Panel);
JPanel number3Panel = new JPanel();
number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Stock: " );
number3Panel.add(jl);
jtfStock = new JTextField(21);
jtfStock.setEditable(false);
number3Panel.add(jtfStock);
outerPanel.add(number3Panel);
JPanel number4Panel = new JPanel();
number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Restocking Fee: $ " );
number4Panel.add(jl);
jtfReStock = new JTextField(21);
jtfReStock.setEditable(false);
number4Panel.add(jtfReStock);
outerPanel.add(number4Panel);
JPanel number5Panel = new JPanel();
number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Price: $ " );
number5Panel.add(jl);
jtfPrice = new JTextField(21);
jtfPrice.setEditable(false);
number5Panel.add(jtfPrice);
outerPanel.add(number5Panel);
JPanel number6Panel = new JPanel();
number6Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Value: $ " );
number6Panel.add(jl);
jtfValue = new JTextField(21);
jtfValue.setEditable(false);
number6Panel.add(jtfValue);
outerPanel.add(number6Panel);
JPanel number7Panel = new JPanel();
number7Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Total Invenory Value: $" );
number7Panel.add(jl);
jtftotalInv = new JTextField(21);
jtftotalInv.setEditable(false);
number7Panel.add(jtftotalInv);
outerPanel.add(number7Panel);
Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
btnIcon = new JButton ( "DVD",dvd);
add( btnIcon );
btnFirst = new JButton( "First" );
add( btnFirst );
btnPrevious = new JButton( "Previous" );
add( btnPrevious );
btnNext = new JButton( "Next" );
add( btnNext );
btnLast = new JButton( "Last" );
add( btnLast );
ButtonHandler handler = new ButtonHandler();
btnIcon.addActionListener( handler );
btnFirst.addActionListener( handler );
btnPrevious.addActionListener( handler );
btnNext.addActionListener( handler );
btnLast.addActionListener( handler );
setContentPane(outerPanel);
setResizable(false);
setSize(800, 800);
setVisible(true);
}
void setDVD(DVD[] dvd) {
// keep the movies
this.dvd = dvd;
index = 0;
display();
}
void display() {
jtfVideo.setText("" + dvd[index].getVideo());
jtfRating.setText("" + dvd[index].getRating());
jtfitmNumber.setText("" + dvd[index].getNumber());
jtfStock.setText("" + dvd[index].getStock());
jtfReStock.setText("" + dvd[index].getRestockingFee());
jtfPrice.setText("" + dvd[index].getPrice());
jtfValue.setText("" + dvd[index].getValue());
jtftotalInv.setText("" );
}
// to display next movie
void displayNext() {
index++;
if(index >= dvd.length) // wrap around
index = 0;
display();
}
// display previous
void displayPrevious() {
index--;
if(index < 0) // wrap around
index = dvd.length - 1;
display();
}
} // end GUI1 class
CODE
//Overloaded constructors used to initialize inventory
import java.lang.String;
import java.text.DecimalFormat;
import java.awt.FlowLayout; // specifies how components are arranged
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
public class Inventory1Test
{
static DecimalFormat formatter = new DecimalFormat("$##,###.00");
public static void main( String args[] )
{
DVD[] library = new DVD[4];
library[0] = new DVD( "1", "Star Wars", "PG", 232, 5, 13.45);
library[1] = new DVD("2", "Cars", "G", 233, 7, 12.23 );
library[2] = new DVD("3", "Fantastic Four", "PG", 234, 8, 18.45);
library[3] = new DVD("4", "Batman", "PG-13", 235, 2, 10.88);
GUI1 gui1 = new GUI1();
gui1.setDVD(library);
for (int index = 0; index < library.length; index++)
{
}//end
library[0].SortInventory1(library);
for (int index = 0; index < library.length; index++)
{
}//end
Double totalInv = library[0].CalculateTotalInventoryValue(library);
//Double restockingFee = library[index].getRestockingFee();
//System.out.printf( "Restocking Fee(5%): \t%s\n\n", library[index].getRestockingFee());
}//end main
}//end class Inventory1Test