Hi Everyone I am new and just found this site yesturday I am looking forward to visiting here often.
I have been working on this project (yes for school the awful Inventory Program.)
I had it working and did a couple of quick changes walked away for a nap and now it won't launch the GUI and I didn't take notes on what I did.
Everything looks like it is there so now I am going through my code and checking to see if something is causing it not to launch or if I accidently deleted something when I was cleaning it up to turn in.
I was just wondering if I could invite you to look with me :$
I feel so stupid about this but I am so tired and my brain is mush :zzz:
I thank those who are up to the challenge in advance.
Here is my code
package inventoryfinal;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
public class Inventory {
private String inventoryName; // name of inventory
public String restockRate; // restock rate percentage
public double totalRestock;
public static int index;
public ArrayList < ProductModified > products = new ArrayList < ProductModified > ();
public Inventory()
{
products.add( new ProductModified( "Wanted", 0, 1, 0.00 ) );
products.add( new ProductModified( "Death Race", 7, 52, 160.00 ) );
products.add( new ProductModified( "Harry Potter", 16, 61, 97.00 ) );
products.add( new ProductModified( "Repo", 25, 106, 88.00 ) );
products.add( new ProductModified( "Matrix", 34, 125, 79.00 ) );
products.add( new ProductModified( "Mamma Mia", 0, 124, 70.00 ) );
index = 0;
}
public void sort()
{
Locale loc = Locale.ENGLISH;
ProductModified Temp;
Collator col = Collator.getInstance( loc );
for ( int i = 0; i < products.size(); i++ )
{
for ( int j = i + 1; j < products.size(); j++ )
{
if( col.compare( products.get( i ).getDVDName(), products.get( j ).getDVDName() ) > 0 )
{
Temp = products.get( i );
products.set( i, products.get( j ) );
products.set( j, Temp );
}
}
}
}
public String getInventoryName()
{
return inventoryName;
}
public void setInventoryName( String inventoryName )
{
this.inventoryName = inventoryName;
}
public String getRestockRate()
{
return restockRate;
}
public void setRestockRate( String restockRate )
{
this.restockRate = restockRate;
}
public double getTotalRestock()
{
return totalRestock;
}
public void setTotalRestock( double totalRestock )
{
this.totalRestock = totalRestock;
}
public ArrayList < ProductModified > getproducts()
{
return products;
}
public void seproducts( ArrayList < ProductModified > products)
{
this.products = products;
}
@Override
public String toString()
{
String DVDSub = new String(" ");
DVDSub = "Welcome to the\n" + getInventoryName() + "!\n\n";
DVDSub = DVDSub + "Below is the available inventory:\n\n";
DVDSub = DVDSub + "The restock interest rate is at " + getRestockRate() + ".\n\n";
DVDSub = DVDSub + "Index\tProductModified #\t\t\tName\t\tUnits\t\tPrice\t\t";
DVDSub = DVDSub + "Unit Restock Value\t";
DVDSub = DVDSub + "Stock Value\t\t";
DVDSub = DVDSub + "Total ProductModified Restock\n";
Iterator < ProductModified > i = this.getproducts().iterator();
while(i.hasNext())
{
DVDSub = DVDSub + i.next();
}
return DVDSub;
}
public Double getTotal()
{
Double Total = 0.0;
ProductModified p;
Iterator < ProductModified > i = products.iterator();
while( i.hasNext() )
{
p = i.next();
Total = Total + p.getPrice() * p.getUnit();
}
return Total;
}
public String processOutPut( ProductModified p )
{
String out = "Welcome Mari's Inventory\n\nTotal Inventory = "
+ this.getTotal() + "\nRestocking Fee = 5%"
+ "\n\nItem #\tName\tUnit\tPrice\tUnit Restock Value"
+ p;
return out;
}
public String getFirst()
{
index = 0;
return processOutPut( products.get(0) );
}
public String getLast()
{
index = products.size() - 1;
return processOutPut( products.get( products.size() - 1 ) );
}
public String getNext()
{
if( index == products.size() - 1 )
{
getFirst();
return getFirst();
}
else
{
index++;
return processOutPut( products.get( index ) );
}
}
public String getPrevious()
{
if( index == 0 )
{
return getLast();
}
else {
return processOutPut(products.get(--index));
}
}
public String Search( String Search )
{
Iterator < ProductModified > i = products.iterator();
String te = null;
ProductModified p;
while( i.hasNext() )
{
p = i.next();
if( p.getDVDName().equals( Search ) )
{
te = processOutPut( p );
}
}
return te;
}
}
package inventoryfinal;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class InventoryDialogue extends JFrame implements ActionListener{
private boolean status = false; //false is for modify
JTextField nameTextField,
unitTextField,
priceTextField;
JLabel nameLabel,
unitLabel,
priceLabel;
JPanel TextFields,
buttons;
JButton modify,
add;
public InventoryDialogue( Boolean stat, String title )
{
super( title );
status = stat;
JPanel but = new JPanel();
modify = new JButton( "Modify" );
modify.addActionListener( this );
add = new JButton( "Add" );
add.addActionListener( this );
but.add( add );
but.add( modify );
if( status == false )
{
add.setVisible( false );
}
else
{
modify.setVisible( false );
}
nameTextField = new JTextField( "", 20 );
unitTextField = new JTextField( "", 5 );
priceTextField = new JTextField( "" , 5 );
nameLabel = new JLabel( "Name" );
unitLabel = new JLabel( "Units" );
priceLabel = new JLabel( "Price per Unit" );
JPanel p = new JPanel();
p.setLayout( new FlowLayout() );
p.add( nameLabel );
p.add( nameTextField );
p.add( unitLabel );
p.add( unitTextField );
p.add( priceLabel );
p.add( priceTextField );
JPanel cp = new JPanel();
cp.setLayout( new BorderLayout() );
cp.add( p, BorderLayout.CENTER );
cp.add( but, BorderLayout.EAST );
this.setContentPane( cp );
this.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
this.pack();
this.setVisible( true );
}
@Override
public void actionPerformed( ActionEvent arg0 )
{
if( arg0.getActionCommand().equals( "Add" ) )
{
String name;
int units;
Double price;
name = nameTextField.getText();
try
{
units = Integer.parseInt( unitTextField.getText() );
}
catch ( NumberFormatException e )
{
JOptionPane.showMessageDialog( null, e.getMessage() );
e.printStackTrace();
return;
}
try
{
price = Double.parseDouble( priceTextField.getText() );
}
catch ( NumberFormatException e )
{
// TODO Auto-generated catch block
JOptionPane.showMessageDialog( null, e.getMessage() );
e.printStackTrace();
return;
}
InventoryGUI.getInv().getproducts().add( new ProductModified( name, InventoryGUI.getInv().products.size(),
units,price ) );
this.dispose();
}
if( arg0.getActionCommand().equals( "Modify" ) )
{
String name;
int units;
Double price;
name = nameTextField.getText();
try
{
units = Integer.parseInt( unitTextField.getText() );
}
catch ( NumberFormatException e )
{
JOptionPane.showMessageDialog( null,"Please Enter Valid Integers" );
e.printStackTrace();
return;
}
try
{
price = Double.parseDouble( priceTextField.getText() );
}
catch ( NumberFormatException e )
{
// TODO Auto-generated catch block
JOptionPane.showMessageDialog( null,"Please Enter Valid Price" );
//e.printStackTrace();
return;
}
InventoryGUI.getInv().getproducts().set( Inventory.index,
new ProductModified( name, Inventory.index, units, price ) );
this.dispose();
}
}
public static void main( String args[] )
{
InventoryDialogue idf = new InventoryDialogue( true,"cc" );
}
}
package inventoryfinal;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class InventoryGUI extends JFrame implements ActionListener{
private JTextArea textArea;
private JButton first,
next,
previous,
last,
add,
modify,
delete,
save,
search,
exit;
JLabel imageLabel;
private static Inventory inv = new Inventory();
public InventoryGUI( String arg0 ) throws HeadlessException
{
super( "Inventory GUI" );
textArea = new JTextArea( 250,30 );
JScrollPane scrollPane = new JScrollPane( textArea );
textArea.setEditable( false );
scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
scrollPane.setPreferredSize( new Dimension( 250, 250 ) );
JPanel cp = new JPanel();
cp.setSize( 250, 40 );
cp.setLayout( new BorderLayout() );
cp.add( scrollPane,BorderLayout.CENTER );
JPanel buttonPaenl = new JPanel();
JPanel buttonPaenl1 = new JPanel();
first = new JButton( "First" );
first.addActionListener( this );
search = new JButton( "Search" );
search.addActionListener( this );
next = new JButton( "Next" );
next.addActionListener( this );
previous = new JButton( "Previous" );
previous.addActionListener( this );
last = new JButton( "Last" );
last.addActionListener( this );
add = new JButton( "Add" );
add.addActionListener( this );
modify = new JButton( "Modify" );
modify.addActionListener( this );
delete = new JButton( "Delete" );
delete.addActionListener( this );
save = new JButton( "Save" );
save.addActionListener( this );
exit = new JButton( "Exit" );
exit.addActionListener( this );
buttonPaenl.setLayout( new FlowLayout() );
buttonPaenl1.setLayout( new FlowLayout() );
buttonPaenl.add( first );
buttonPaenl.add( previous );
buttonPaenl.add( next );
buttonPaenl.add( last );
buttonPaenl1.add( add );
buttonPaenl1.add( modify );
buttonPaenl1.add( delete );
buttonPaenl1.add( save );
buttonPaenl1.add( search );
buttonPaenl1.add( exit );
cp.add( buttonPaenl,BorderLayout.SOUTH );
cp.add( buttonPaenl1,BorderLayout.NORTH );
cp.add( imageLabel,BorderLayout.EAST );
this.setContentPane( cp );
this.setTitle( " Week Nine Final Project: Inventory Program Part Six - Mari's Movies " );
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
this.textArea.setText(inv.getFirst());
this.setSize(400, 400);
this.pack();
this.setVisible( true );
Container pane = getContentPane();
pane.setLayout(new GridLayout (4, 2));
}
@Override
public void actionPerformed( ActionEvent e )
{
if( e.getActionCommand().equals( "First" ) )
{
textArea.setText( inv.getFirst() );
}
if( e.getActionCommand().equals( "Next" ) )
{
textArea.setText(inv.getNext());
}
if( e.getActionCommand().equals( "Previous" ) )
{
textArea.setText( inv.getPrevious() );
}
if( e.getActionCommand().equals( "Last" ) )
{
textArea.setText(inv.getLast());
}
if( e.getActionCommand().equals( "Save" ) )
{
save();
}
if( e.getActionCommand().equals( "Exit" ) )
{
System.exit(0);
}
if( e.getActionCommand().equals( "Add" ) )
{
InventoryDialogue id = new InventoryDialogue( true," Add a new Inventory " );
}
if( e.getActionCommand().equals( "Modify" ) )
{
InventoryDialogue id = new InventoryDialogue( false," Modify Inventory " );
}
if( e.getActionCommand().equals( "Search" ) )
{
String s = JOptionPane.showInputDialog( null, " Enter Product Name ",null, 1 );
s = inv.Search(s);
if( s == null )
{
JOptionPane.showMessageDialog( this, " No Results Found " );
}
else {
textArea.setText(s);
}
}
if( e.getActionCommand().equals( "Delete" ) )
{
inv.getproducts().remove( Inventory.index );
}
}
public void save()
{
File f = new File( "C:\\data\\inventory.dat" );
try
{
FileOutputStream out = new FileOutputStream( f );
try
{
ObjectOutputStream objectOut = new ObjectOutputStream( out );
objectOut.writeObject( inv );
}
catch (IOException e)
{
// TODO Auto-generated catch block
JOptionPane.showMessageDialog( null, e.getMessage() );
e.printStackTrace();
}
}
catch ( FileNotFoundException e )
{
// TODO Auto-generated catch block
JOptionPane.showMessageDialog( null, e.getMessage() );
e.printStackTrace();
}
}
public static Inventory getInv()
{
return inv;
}
public static void setInv( Inventory inv )
{
InventoryGUI.inv = inv;
}
public static void main( String[] args )
{
InventoryGUI inventory = new InventoryGUI( "Inventory" );
}
}
package inventoryfinal;
public class Product {
public static void main(String[] args) {
}
public int productNumber; // product # array ID for product
public int unit; // array of autobot toy units
public double price; // array of autobot prices
public double inventoryValue;
private String DVDName;
public Product( String DVDName, int productNumber, int unit,
double price )
{
super();
this.DVDName = DVDName;
this.productNumber = productNumber;
this.unit = unit;
this.price = price;
}
public String getDVDName()
{
return DVDName;
}
public void setDVDName( String autobotName )
{
this.DVDName = autobotName;
}
public int getProductNumber()
{
return productNumber;
}
public void setProductNumber( int productNumber )
{
this.productNumber = productNumber;
}
public int getUnit()
{
return unit;
}
public void setUnit( int unit )
{
this.unit = unit;
}
public double getPrice()
{
return price;
}
public void setPrice( double price )
{
this.price = price;
}
public double getInventoryValue()
{
return inventoryValue;
}
public Double inventoryValue()
{
return this.getPrice() * this.getUnit();
}
@Override
public String toString()
{
return "\n"+this.productNumber+"\t"+this.DVDName+"\t"+this.unit +"\t"+this.price+ "\t";
}
}
package inventoryfinal;
public class ProductModified extends Product{
private String MovieName;
public ProductModified( String DVDName, int productNumber, int unit,
double price )
{
super( DVDName, productNumber, unit, price );
this.inventoryValue = this.inventoryValue();
}
public Double inventoryValue()
{
return this.getUnit() * this.getPrice() + this.getUnit() * this.getPrice() * 0.05;
}
public String toString()
{
return "\n" + this.productNumber + "\t" + this.MovieName
+ "\t" + this.unit + "\t" + this.price + "\t"
+ this.getInventoryValue();
}
}
:*