I can get my labels to work but I can't get my data from the rest of my program to compile into my GUI. In the reading that we were given on this topic it does not show us how to get the data. It only shows how to type the data in line by line, but I know there has to be an easier way.
CODE
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.SwingConstants;
public class LabelFrame extends JFrame
{
private JLabel label1; // JLabel Non sorted DVD Inventory
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 JLabel label11; // JLabel Sorted DVD Inventory
private JLabel label12; // JLabel Item number
private JLabel label13; // JLabel Title of Movie
private JLabel label14; // JLabel Movie Rating
private JLabel label15; // JLabel Stock Number
private JLabel label16; // JLabel Number of Item in Stock
private JLabel label17; // JLabel Restocking Fee
private JLabel label18; // JLabel Purchase Price
private JLabel label19; // JLabel Inventory Value
private JLabel label20; // JLabel Total Inventory Value
int index = 0;
// LabelFrame constructor adds JLabels to JFrame
public LabelFrame()
{
super( "Inventory of DVD Movies" );
setLayout( new FlowLayout() ); // set frame layout
// JLabel constructor with a string argument
label1 = new JLabel("<html><font size=+1>Non sorted DVD inventory</html>");
label1.setHorizontalTextPosition( SwingConstants.CENTER );
label1.setVerticalTextPosition( SwingConstants.CENTER );
add( label1 ); // add label1 to JFrame
label2 = new JLabel( "\nItem#: " );
label2.setHorizontalTextPosition( SwingConstants.LEFT );
label2.setVerticalTextPosition( SwingConstants.TOP );
add( label2 ); // add label2 to JFrame
label3 = new JLabel( "\nTitle of Movie: ");
add( label3 ); // add label3 to JFrame
label4 = new JLabel("\nMovie Rating:");
add( label4 );
label5 = new JLabel("\nItem Number:");
add( label5 );
label6 = new JLabel( "\n# of Items in Stock:");
add( label6 );
label7 = new JLabel( "\nRestocking Fee:" );
add( label7 );
label8 = new JLabel( "\nPurchase Price:");
add( label8 );
label9 = new JLabel( "\nInventory Value:");
add( label9 );
label10 = new JLabel( "\nTotal Inventory Value:\n");
add( label10 );
label11 = new JLabel("<html><font size=+1>\nSorted DVD inventory</html>");
label11.setHorizontalTextPosition( SwingConstants.CENTER );
label11.setVerticalTextPosition( SwingConstants.CENTER );
add(label11 );
label12 = new JLabel( "\nItem#:" );
label12.setHorizontalTextPosition( SwingConstants.LEFT );
label12.setVerticalTextPosition( SwingConstants.TOP );
add( label12 ); // add label2 to JFrame
label13 = new JLabel( "\nTitle of Movie:");
add( label13 ); // add label3 to JFrame
label14 = new JLabel("\nMovie Rating:");
add( label14 );
label15 = new JLabel("\nItem Number:");
add( label15 );
label16 = new JLabel( "\n# of Items in Stock:");
add( label16 );
label17 = new JLabel( "\nRestocking Fee:" );
add( label17 );
label18 = new JLabel( "\nPurchase Price:");
add( label18 );
label19 = new JLabel( "\nInventory Value:");
add( label19 );
label20 = new JLabel( "\nTotal Inventory Value:");
add( label20 );
setSize(1200,300);
setVisible(true);
} // end LabelFrame constructor
public static void main(String args[])
{
LabelFrame f = new LabelFrame();
}
} // end class LabelFrame
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);
System.out.println( "\nInventory of DVD Movies: " );
for (int index = 0; index < library.length; index++)
{
System.out.printf( "\nItem #%s ", library[index].getItems());
System.out.printf( "\nTitle of Movie: \t%s", library[index].getVideo());
System.out.printf( "\nMovie Rating: \t\t%s", library[index].getRating() );
System.out.printf( "\nItem Number: \t\t%s", library[index].getNumber());
System.out.printf( "\n# of Items in Stock: \t%s", library[index].getStock());
System.out.printf( "\nRestocking Fee: \t%s", library[index].getRestockingFee() );
System.out.printf( "\nPurchase Price: \t$%s", library[index].getPrice());
System.out.printf( "\nInventory Value: \t$%s\n\n", library[index].getValue());
}//end
library[0].SortInventory1(library);
System.out.println( "\nSorted Inventory of DVD Movies:");
for (int index = 0; index < library.length; index++)
{
System.out.printf( "\nItem #%s ", library[index].getItems());
System.out.printf( "\nTitle of Movie: \t%s", library[index].getVideo());
System.out.printf( "\nMovie Rating: \t\t%s", library[index].getRating() );
System.out.printf( "\nItem Number: \t\t%s", library[index].getNumber());
System.out.printf( "\n# of Items in Stock: \t%s", library[index].getStock());
System.out.printf( "\nRestocking Fee: \t%s", library[index].getRestockingFee() );
System.out.printf( "\nPurchase Price: \t$%s", library[index].getPrice());
System.out.printf( "\nInventory Value: \t$%s\n\n", library[index].getValue());
}//end
Double totalInv = library[0].CalculateTotalInventoryValue(library);
System.out.printf( "Total Inventory Value: \t$%s\n\n", totalInv );
//Double restockingFee = library[index].getRestockingFee();
//System.out.printf( "Restocking Fee(5%): \t%s\n\n", library[index].getRestockingFee());
}//end main
}//end class Inventory1Test