I have been trying to get this inventory program GUI to properly work. Several issues I am running into are:
Inability to pull my supplies into the GUI and be displayed from my main program.
Unable to get the buttons to work properly. (the quit button works)
My inventory should pop up when the program runs and the buttons should cycle correctly.
If I run my main program by itself, I get only a Gui box, nothing filled in it so something isnt being passed and I dont understand why.
I believe when I run my main program, The gui should run as well but im not sure how to get it to do that.
I honestly dont know how to compile my program ( im very noob with java and in dire need of a walkthrough)
I will post my code, but if there is someone who can offer me assistance and walk through this with me either on the phone, skype or something, it would be of great help. Feel free to tear into it and let me know in detail if you can what i need to change. Any help is appreciated.
Main Program***
GUI***
Inability to pull my supplies into the GUI and be displayed from my main program.
Unable to get the buttons to work properly. (the quit button works)
My inventory should pop up when the program runs and the buttons should cycle correctly.
If I run my main program by itself, I get only a Gui box, nothing filled in it so something isnt being passed and I dont understand why.
I believe when I run my main program, The gui should run as well but im not sure how to get it to do that.
I honestly dont know how to compile my program ( im very noob with java and in dire need of a walkthrough)
I will post my code, but if there is someone who can offer me assistance and walk through this with me either on the phone, skype or something, it would be of great help. Feel free to tear into it and let me know in detail if you can what i need to change. Any help is appreciated.
Main Program***
// This program calculates inventory value
/**
*
* @author Keith
*/
import javax.swing.*;
import java.util.Arrays;
public class InventoryProgramPart3{
// main method begins program execution
public static void main(String args[] )
{
// display a welcome message to the InventoryProgramPart3 user
System.out.println( "Welcome to Inventory Program Part 3!" );
// office supplies
//supplies[] supplies = new supplies[5];
supplies [] suppliesArray;
suppliesArray = new supplies[5];
supplies notepads = new supplies( 1712, "notepads", 60, 2.75 );
supplies pencils = new supplies( 1679, "pencils", 75, 1.25 );
supplies folders = new supplies( 2651, "folders", 30, 4.75 );
supplies envelopes = new supplies( 7884, "envelopes", 15, 5.25 );
supplies markers = new supplies( 2115, "markers", 45, 3.50 );
// display the inventories one at a time
envelopes.showInventory();
folders.showInventory();
markers.showInventory();
notepads.showInventory();
pencils.showInventory();
// sort supplies by name
for ( int i = 0; i < args.length; i++ ) {
System.out.println( args[i] + ", " );
}
double array[] = { 78.75, 142.50, 157.50, 165.00, 93.75 };
double total = 0;
// add each element's value to total
for ( int counter = 0; counter < array.length; counter++) {
total += array[ counter ];
}
System.out.printf( "\nTotal inventory value is: $%.2f\n", total );
System.out.println( "\nThank you for using Inventory Program Part 5!\n" );
JFrame suppliesGUI=new JFrame();
suppliesGUI.setVisible(true);
suppliesGUI.setSize(600, 400);
} //end method main
} // end class InventoryProgramPart3
// Office Supplies
class supplies
{
public int suppliesNumber;
public String suppliesName = new String();
public int suppliesUnits;
public double suppliesPrice;
// set supplies number
public void setSuppliesNumber( int number )
{
this.suppliesNumber = number;
} // end method set supplies number
// return supplies number
public int getSuppliesNumber()
{
return suppliesNumber;
} // end method get supplies number
// set supplies name
public void setSuppliesName( String name )
{
this.suppliesName = name;
} // end method set supplies name
// return supplies name
public String getSuppliesName()
{
return suppliesName;
} // end method get supplies name
// set supplies in stock
public void setSuppliesUnits( int units )
{
this.suppliesUnits = units;
} // end method set supplies units
// return supplies units
public int getSuppliesUnits()
{
return suppliesUnits;
} // end method get supplies units
// set supplies price
public void setSuppliesPrice( double price )
{
this.suppliesPrice = price;
} // end method set supplies price
// return supplies price
public double getSuppliesPrice()
{
return suppliesPrice;
} // end method get supplies price
// calculate supplies inventory value
public double getValue()
{
return suppliesUnits * suppliesPrice;
} // end method supplies inventory value
// four-argument constructor
supplies( int number, String name, int units, double price )
{
suppliesNumber = number;
suppliesName = name;
suppliesUnits = units;
suppliesPrice = price;
} // end four-argument constructor
// display inventory
public void showInventory()
{
System.out.println(); // outputs blank line
System.out.println( "Product Number: "+suppliesNumber );
System.out.println( "Product Name: "+suppliesName );
System.out.println( "Units in Stock: "+suppliesUnits );
System.out.printf( "Unit Price: $%.2f", suppliesPrice );
// value() method and display the value
System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
getValue() );
} // end display inventory
} // end class supplies
GUI***
//Checkpoint: Inventory Program Part 5
//Implement GUI interface
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
class suppliesGUI extends JFrame implements ActionListener //define class
{
public static JButton enterButton;
public static JButton quitButton;
public static JButton showButton;
public static JButton previousButton;
public static JButton nextButton;
public static JButton addButton;
public static JButton deleteButton;
public static JButton modifyButton;
public static JButton saveButton;
public static JButton searchButton;
public static JTextField ProductNameField;
public static JTextField ProductNumberField;
public static JTextField ProductPriceField;
public static JTextField ProductQuantityField;
public static JTextArea ProductArea;
public static ArrayList<supplies> suppliesArray = new ArrayList<supplies>();
public suppliesGUI()
{
super ( "suppliesGUI" );
supplies [] suppliesArray;
suppliesArray = new supplies[6];
Container con = getContentPane();
BoxLayout layout = new BoxLayout(con, BoxLayout.Y_AXIS);
con.setLayout(layout);
JPanel topPanel= new JPanel();
JPanel bottomPanel= new JPanel();
con.add(topPanel, BorderLayout.NORTH);
con.add(bottomPanel, BorderLayout.SOUTH);
Box lBoxUpperL= new Box(BoxLayout.Y_AXIS);
Box lBoxUpperR= new Box(BoxLayout.Y_AXIS);
Box lBoxLowerL= new Box(BoxLayout.Y_AXIS);
Box lBoxLowerR= new Box(BoxLayout.Y_AXIS);
topPanel.add(lBoxUpperL);
topPanel.add(lBoxUpperR);
bottomPanel.add(lBoxLowerL);
bottomPanel.add(lBoxLowerR);
JLabel ProductNameLabel = new JLabel( "Product Name :" );
ProductNameField = new JTextField("",50);
JLabel ProductNumberLabel = new JLabel( " Product Number:" );
ProductNumberField = new JTextField("",20);
JLabel ProductPriceLabel = new JLabel( " Product Price:" );
ProductPriceField = new JTextField("",6);
JLabel ProductQuantityLabel = new JLabel( "# in stock:" );
ProductQuantityField = new JTextField("",3);
JLabel ProductLabel = new JLabel("Product List");
ProductArea = new JTextArea ();
lBoxUpperL.add(ProductNameLabel);
lBoxUpperL.add(ProductNameField);
lBoxUpperL.add(ProductNumberLabel);
lBoxUpperL.add(ProductNumberField);
lBoxUpperL.add(ProductPriceLabel);
lBoxUpperL.add(ProductPriceField);
lBoxUpperL.add(ProductQuantityLabel);
lBoxUpperL.add(ProductQuantityField);
lBoxUpperL.add(ProductLabel);
lBoxUpperL.add(ProductArea);
enterButton = new JButton("Enter");
enterButton.addActionListener (this);
showButton = new JButton("Show");
showButton.addActionListener (this);
quitButton = new JButton("Quit");
quitButton.addActionListener (this);
previousButton = new JButton ("Previous") ;
previousButton.addActionListener(this);
nextButton = new JButton ("Next") ;
nextButton.addActionListener(this);
addButton = new JButton("Add");
addButton.addActionListener (this);
deleteButton = new JButton("Delete");
deleteButton.addActionListener (this);
modifyButton = new JButton("Modify");
modifyButton.addActionListener (this);
searchButton = new JButton ("Search") ;
searchButton.addActionListener(this);
saveButton = new JButton ("Save") ;
saveButton.addActionListener(this);
lBoxUpperL.add(enterButton);
lBoxUpperL.add(showButton);
lBoxUpperR.add(quitButton);
lBoxLowerR.add(nextButton);
lBoxLowerL.add(previousButton);
lBoxUpperL.add(addButton);
lBoxUpperL.add(deleteButton);
lBoxUpperR.add(modifyButton);
lBoxLowerR.add(searchButton);
lBoxLowerL.add(saveButton);
//Pack the graphics output and set it to visible
pack();
setVisible( true);
//Create a Close Button Listener Class
class CloseButtonListener implements ActionListener
{
@Override
public void actionPerformed( ActionEvent e)
{
//This closes the current JFrame Window
suppliesGUI.this.dispose();
}
}
quitButton.addActionListener( new CloseButtonListener());
setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE);
addWindowListener( new WindowAdapter()
{
@Override
public void windowClosed(WindowEvent e)
{
//This outputs into the command line window so we can terminate the Java app
System.out.println( "Thanks for playing!");
System.exit(0);
}
}
);
}
public static void main(String args []) //main method
{
/* Create an Instance of the class */
suppliesGUI myFrame;
myFrame = new suppliesGUI();
myFrame.setSize(600,400);
}
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}