I have my if loop but It isn't working..which means I messed up again
Can someone help me Please!!!
CODE
import javax.swing.JOptionPane;
import java.awt.FlowLayout; // specifies how components are arranged
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.Box;
public class GUI extends JFrame
{
private JLabel label2; // JLabel Item number
private JLabel label3; // JLabel Title of Movie
private JLabel label4; // JLabel Movie Rating
private JLabel label5; // JLabel Stock Number
private JLabel label6; // JLabel Number of Item in Stock
private JLabel label7; // JLabel Restocking Fee
private JLabel label8; // JLabel Purchase Price
private JLabel label9; // JLabel Inventory Value
private JLabel label10; // JLabel Total Inventory Value
private JTextField jtfItem;
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 JLabel label11; //JLabel icon
private JButton btnFirst;
private JButton btnPrevious;
private JButton btnNext;
private JButton btnLast;
DVD[] dvd;
int index = 0;
// LabelFrame constructor adds JLabels to JFrame
public GUI()
{
super( "Inventory of DVD Movies" );
// JLabel constructor with a string argument
//this.inventory1 = inventory1;
JLabel jl;
JPanel jp;
setLayout( new FlowLayout() ); // set frame layout
label2 = new JLabel("Item#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfItem = new JTextField (30);
jtfItem.setEditable(false);
add( label2 ); // add label2 to JFrame
add(jtfItem);
label3 = new JLabel( "Title of Movie: ");
label3.setHorizontalTextPosition( SwingConstants.RIGHT );
label2.setVerticalTextPosition( SwingConstants.CENTER );
jtfVideo = new JTextField (30);
jtfVideo.setEditable(false);
add( label3 ); // add label2 to JFrame
add(jtfVideo);
label4 = new JLabel("Movie Rating:");
label4.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfRating = new JTextField (30);
jtfRating.setEditable(false);
add( label4 ); // add label2 to JFrame
add(jtfRating);
label5 = new JLabel("Item Number:");
label5.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfitmNumber = new JTextField (30);
jtfitmNumber.setEditable(false);
add( label5 ); // add label2 to JFrame
add(jtfitmNumber);
label6 = new JLabel( "# of Items in Stock:");
label6.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfStock = new JTextField (30);
jtfStock.setEditable(false);
add( label6 ); // add label2 to JFrame
add(jtfStock);
label7 = new JLabel( "Restocking Fee:" );
label7.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfReStock = new JTextField (30);
jtfReStock.setEditable(false);
add( label7 ); // add label2 to JFrame
add(jtfReStock);
label8 = new JLabel( "Purchase Price:");
label8.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfPrice = new JTextField (30);
jtfPrice.setEditable(false);
add( label8 ); // add label2 to JFrame
add(jtfPrice);
label9 = new JLabel( "Inventory Value:");
label9.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtfValue = new JTextField (30);
jtfValue.setEditable(false);
add( label9 ); // add label2 to JFrame
add(jtfValue);
label10 = new JLabel( "Total Inventory Value:\n");
label10.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
jtftotalInv = new JTextField (30);
jtftotalInv.setEditable(false);
add( label10 ); // add label2 to JFrame
add(jtftotalInv);
Icon dvd = new ImageIcon(getClass().getResource( "dvd.jpg" ));
label11 = new JLabel ( dvd, SwingConstants.LEFT);
label11.setVerticalTextPosition( SwingConstants.TOP);
add( label11 );
btnFirst = new JButton( "First" );
add( btnFirst );
btnPrevious = new JButton( "Previous" );
add( btnPrevious );
btnNext = new JButton( "Next" );
add( btnNext );
btnLast = new JButton( "Last" );
add( btnLast );
setSize(800,500);
setVisible(true);
} // end LabelFrame constructor
void setDVD(DVD[] dvd)
{
this.dvd = dvd;
index = 0;
display();
}
void display() {
jtfItem.setText("" + dvd[index].getItems());
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 class GUI
CODE
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
import javax.swing.JTextField;
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);
GUI gui = new GUI();
gui.setDVD(library);
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