11 Replies - 734 Views - Last Post: 21 June 2008 - 02:06 PM Rate Topic: -----

#1 smithgang1994  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 30-May 08

Getting my Calculate total inventory into my GUI

Post icon  Posted 21 June 2008 - 11:21 AM

My calculate total inventory worked before I created my GUI. Now I cant figure out how to code it into my gui to work. this is the error I get.

C:\Users\Michael\Desktop\java6\GUI.java:212: CalculateTotalInventoryValue(Inventory1[]) in Inventory1 cannot be applied to ()
jtftotalInv.setText("" + dvd[index].CalculateTotalInventoryValue());


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 implements ActionListener
{

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;
private JButton	btnAdd;
private JButton btnDelete;
private JButton btnModify;
private JButton btnSave;
private JButton btnSearch;
private JButton btnLoadfile;
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" );
btnFirst.addActionListener(this);
add( btnFirst );


btnPrevious = new JButton( "Previous" );
btnPrevious.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext );

btnLast = new JButton( "Last" );
btnLast.addActionListener(this);
add( btnLast );

btnAdd = new JButton( "Add" );
btnAdd.addActionListener(this);
add( btnAdd );

btnDelete = new JButton( "Delete" );
btnDelete.addActionListener(this);
add( btnDelete );

btnModify = new JButton( "Modify" );
btnModify.addActionListener(this);
add( btnModify );

btnSave = new JButton( "Save" );
btnSave.addActionListener(this);
add( btnSave );

btnSearch = new JButton( "Search" );
btnSearch.addActionListener(this);
add( btnSearch );

btnLoadfile = new JButton( "Load file" );
btnLoadfile.addActionListener(this);
add( btnLoadfile );



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("" + dvd[index].CalculateTotalInventoryValue());
}
 // to display next movie
 void displayFirst(){
 		index = 0;
 		display();
	}
	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();
	}



	void displayLast(){
			index = dvd.length - 1;
			display();
		}

 public void actionPerformed(ActionEvent e){
	Object buttonPressed = e.getSource();
	if(buttonPressed == btnFirst){
		index = 0;
		displayFirst();
		return;
	}
	if (buttonPressed == btnNext) {
		displayNext();
		return;
	}
	if (buttonPressed == btnPrevious){
		displayPrevious();
		return;
	}
	if (buttonPressed == btnLast){
		displayLast();
		return;
	}
	display();
}

} // end class GUI


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



Is This A Good Question/Topic? 0
  • +

Replies To: Getting my Calculate total inventory into my GUI

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 11:35 AM

The problem is in your class Inventory1 that you haven't posted
I'll guess you will also have to post your class DVD

But from what it says:

GUI.java:212: CalculateTotalInventoryValue(Inventory1[]) in Inventory1 cannot be applied to ()
jtftotalInv.setText("" + dvd[index].CalculateTotalInventoryValue());

When you do:

jtftotalInv.setText("" + dvd[index].CalculateTotalInventoryValue());

you call the method CalculateTotalInventoryValue() of DVD without parameter
and CalculateTotalInventory expects an array of Inventory1 as parameter...

are you should that instead of writting:

dvd[index].CalculateTotalInventoryValue());

you should not write:

dvd[index].CalculateTotalInventoryValue(dvd)); ?

This is assuming DVD extends Inventory1
And it will make sense... how can you calculate total inventory value calling the method without passing to it the array of all the DVDs
Was This Post Helpful? 0
  • +
  • -

#3 smithgang1994  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 30-May 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 11:48 AM

Thank you that worked....I will be so glad when this class is done....I am so stumped on the next set of directions I dont even know where to start. I am going to try to make some new buttons work..(I was/am smart enought to know how to add them :) so I can see the buttons! Well off I go...I will probably see you soon :crazy:
Was This Post Helpful? 0
  • +
  • -

#4 smithgang1994  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 30-May 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 12:30 PM

In my Inventory program It isnt suppose to display anything till I press the first button. What do I do to fix this?
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 implements ActionListener
{

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;
private JButton	btnAdd;
private JButton btnDelete;
private JButton btnModify;
private JButton btnSave;
private JButton btnSearch;
private JButton btnLoadfile;
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 (10);
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 (5);
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 (20);
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 (10);
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 (10);
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 (10);
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 (10);
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 (10);
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" );
btnFirst.addActionListener(this);
add( btnFirst );


btnPrevious = new JButton( "Previous" );
btnPrevious.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext );

btnLast = new JButton( "Last" );
btnLast.addActionListener(this);
add( btnLast );

btnAdd = new JButton( "Add" );
btnAdd.addActionListener(this);
add( btnAdd );

btnDelete = new JButton( "Delete" );
btnDelete.addActionListener(this);
add( btnDelete );

btnModify = new JButton( "Modify" );
btnModify.addActionListener(this);
add( btnModify );

btnSave = new JButton( "Save" );
btnSave.addActionListener(this);
add( btnSave );

btnSearch = new JButton( "Search" );
btnSearch.addActionListener(this);
add( btnSearch );

btnLoadfile = new JButton( "Load file" );
btnLoadfile.addActionListener(this);
add( btnLoadfile );



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("" + dvd[index].CalculateTotalInventoryValue(dvd));
}
 // to display next movie
 void displayFirst(){
 		index = 0;
 		display();
	}
	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();
	}

	void displayLast(){
			index = dvd.length - 1;
			display();
		}


 public void actionPerformed(ActionEvent e){
	Object buttonPressed = e.getSource();
	if(buttonPressed == btnFirst){
		index = 0;
		displayFirst();
		return;
	}
	if (buttonPressed == btnNext) {
		displayNext();
		return;
	}
	if (buttonPressed == btnPrevious){
		displayPrevious();
		return;
	}
	if (buttonPressed == btnLast){
		displayLast();
		return;
	}
	display();
}

} // end class GUI


Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 12:44 PM

Not there
must be in the DVD class... leftover that you had before you wrote this gorgeous GUI
Was This Post Helpful? 0
  • +
  • -

#6 smithgang1994  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 30-May 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 12:49 PM

its only gorgeous cuz you have helped me tons! here is my dvd classl
public class DVD extends Inventory1 {
	// Holds the rating of the movie
	private String movierating;
	private String items;
	private String video;
	private int number;
	private int stock;
	private double price;

	private double value;


	public DVD( String items, String  video, String rating, int number,  int stock, double price )
	{
		super( items, video, number, stock, price );
	   movierating = rating;

	}
	public String getRating() {
			return movierating;
		}

// Simply gets the base class's value, and figures out the 5% restocking fee only
		public double getRestockingFee() {
//	  return super.getValue() * .05;
			return getPrice()*0.05;
	}

public double getValue()
{
	return(getPrice()*getStock()*1.05);
}//end method getValue



}//end class DVD



and just for kicks here is the original inventory too
//inventory part 1
import java.lang.String;

public class Inventory1
{
	protected String items;
	protected String video;
	protected int number;
	protected int stock;
	protected double price;
	protected double value;

	public Inventory1( String i, String v, int n, int s, double p )
	{
		setItems(i);
		setVideo(v);
		setNumber(n);
		setStock(s);
		setPrice(p);
	}//end Inventory1 five-argument constructor

	public Inventory1( Inventory1 inventory)
	{
		this( inventory.getItems(), inventory.getVideo(), inventory.getNumber(), inventory.getStock(), inventory.getPrice() );
	}//end Inventoryconstructor with a Inventory object argument


	public void setInventory1( String i, String v, int n, int s, double p )
	{
		setItems( i );
		setVideo( v );
		setNumber( n );
		setStock( s );
		setPrice( p );
	}//end method setInventory

	public void setItems( String i )
	{
		items = ( i );
	}//end method setItems

	public void setVideo( String v )
	{
		video = ( v );
	}//end method setVideo

	public void setNumber( int n )
	{
		number = ( n );
	}//end method setNumber

	public void setStock( int s )
	{
		stock = ( s );
	}//end method setStock

	public void setPrice(double p )
	{
		price = ( p );
	}//end method setPrice

	public String getItems()
	{
		return items;
	}//end method getItems

	public String getVideo()
	{
		return video;
	}//end method getVideo

	public int getNumber()
	{
		return number;
	}//end method getNumber

	public int getStock()
	{
		return stock;
	}//end method getStock

	public double getPrice()
	{
		return price;
	}//end method getPrice

	public double getValue()
	{
		return (stock * price);
		}//end method getValue

 public Double CalculateTotalInventoryValue(Inventory1[] product)
 {
  Double total = 0.0;
  for(int index = 0; index < product.length; index++)
  {
   Inventory1 inv = product[index];
   total += inv.getValue();
  }

  return total;
 }



public Inventory1[] SortInventory1 (Inventory1[] theInventory1)
 {
  Inventory1 tmp;

for (int index = 0; index < theInventory1.length; index++)
  {
   for (int anotherindex = index + 1; anotherindex< theInventory1.length; anotherindex++)
   {
	String s1 = theInventory1[index].getVideo();
	String s2 = theInventory1[anotherindex].getVideo();
	if( s1.compareTo(s2) > 0)
	{
	 tmp = theInventory1[index];
	 theInventory1 [index] = theInventory1[anotherindex];
	 theInventory1 [anotherindex] = tmp;
	}
   }
  }
return theInventory1;
 }








}//end class Inventory1



***Wanna help me with the last part of this crazy class too :P ***

View Postpbl, on 21 Jun, 2008 - 12:44 PM, said:

Not there
must be in the DVD class... leftover that you had before you wrote this gorgeous GUI

Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 12:57 PM

Sorry... by saying "display" I though you where talking about
System.out.println("Something");

Here is the culprit

void setDVD(DVD[] dvd)
{
	this.dvd = dvd;
	index = 0;
	display();	  // <------------------------------
}



But I guess it makes sense to display the first one when the program load
if you don't want this behaviour just remove that display(); that is called when you load your GUI with your array of DVD
Was This Post Helpful? 0
  • +
  • -

#8 smithgang1994  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 30-May 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 01:05 PM

I need to learn to go with my instincts..i thought of doing that..but i didnt :D

View Postpbl, on 21 Jun, 2008 - 12:57 PM, said:

Sorry... by saying "display" I though you where talking about
System.out.println("Something");

Here is the culprit

void setDVD(DVD[] dvd)
{
	this.dvd = dvd;
	index = 0;
	display();	  // <------------------------------
}



But I guess it makes sense to display the first one when the program load
if you don't want this behaviour just remove that display(); that is called when you load your GUI with your array of DVD



when i took it out i got an error for my display under the first button

View Postpbl, on 21 Jun, 2008 - 12:57 PM, said:

Sorry... by saying "display" I though you where talking about
System.out.println("Something");

Here is the culprit

void setDVD(DVD[] dvd)
{
	this.dvd = dvd;
	index = 0;
	display();	  // <------------------------------
}



But I guess it makes sense to display the first one when the program load
if you don't want this behaviour just remove that display(); that is called when you load your GUI with your array of DVD



Never mind my typo

View Postsmithgang1994, on 21 Jun, 2008 - 01:03 PM, said:

I need to learn to go with my instincts..i thought of doing that..but i didnt :D

View Postpbl, on 21 Jun, 2008 - 12:57 PM, said:

Sorry... by saying "display" I though you where talking about
System.out.println("Something");

Here is the culprit

void setDVD(DVD[] dvd)
{
	this.dvd = dvd;
	index = 0;
	display();	  // <------------------------------
}



But I guess it makes sense to display the first one when the program load
if you don't want this behaviour just remove that display(); that is called when you load your GUI with your array of DVD



when i took it out i got an error for my display under the first button

View Postpbl, on 21 Jun, 2008 - 12:57 PM, said:

Sorry... by saying "display" I though you where talking about
System.out.println("Something");

Here is the culprit

void setDVD(DVD[] dvd)
{
	this.dvd = dvd;
	index = 0;
	display();	  // <------------------------------
}



But I guess it makes sense to display the first one when the program load
if you don't want this behaviour just remove that display(); that is called when you load your GUI with your array of DVD

Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 01:07 PM

View Postsmithgang1994, on 21 Jun, 2008 - 01:05 PM, said:

when i took it out i got an error for my display under the first button


Which type of error ?
Was This Post Helpful? 0
  • +
  • -

#10 smithgang1994  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 30-May 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 01:16 PM

yeah that was my typo i forgot to put the () behind display. I had taken out the wrong one and when i put it back i forgot to put my (). On my next part I have to create more buttons. If I am correct I just add them the same as before, but my then I just have to figure out how to use them :) Could you possible help me get into the right direction? I will repaste my code with my new buttons.
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 implements ActionListener
{

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;
private JButton	btnAdd;
private JButton btnDelete;
private JButton btnModify;
private JButton btnSave;
private JButton btnSearch;
private JButton btnLoadfile;
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 (10);
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 (5);
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 (20);
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 (10);
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 (10);
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 (10);
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 (10);
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 (10);
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" );
btnFirst.addActionListener(this);
add( btnFirst );


btnPrevious = new JButton( "Previous" );
btnPrevious.addActionListener(this);
add( btnPrevious );

btnNext = new JButton( "Next" );
btnNext.addActionListener(this);
add( btnNext );

btnLast = new JButton( "Last" );
btnLast.addActionListener(this);
add( btnLast );

btnAdd = new JButton( "Add" );
btnAdd.addActionListener(this);
add( btnAdd );

btnDelete = new JButton( "Delete" );
btnDelete.addActionListener(this);
add( btnDelete );

btnModify = new JButton( "Modify" );
btnModify.addActionListener(this);
add( btnModify );

btnSave = new JButton( "Save" );
btnSave.addActionListener(this);
add( btnSave );

btnSearch = new JButton( "Search" );
btnSearch.addActionListener(this);
add( btnSearch );

btnLoadfile = new JButton( "Load file" );
btnLoadfile.addActionListener(this);
add( btnLoadfile );



setSize(800,500);
	 setVisible(true);



} // end LabelFrame constructor


void setDVD(DVD[] dvd)
{
	this.dvd = dvd;
	index = 0;

}
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("" + dvd[index].CalculateTotalInventoryValue(dvd));
}
 // to display next movie
 void displayFirst(){
 		index = 0;
 		display();

	}
	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();
	}

	void displayLast(){
			index = dvd.length - 1;
			display();
		}


 public void actionPerformed(ActionEvent e){
	Object buttonPressed = e.getSource();
	if(buttonPressed == btnFirst){
		index = 0;
		displayFirst();
		return;
	}
	if (buttonPressed == btnNext) {
		displayNext();
		return;
	}
	if (buttonPressed == btnPrevious){
		displayPrevious();
		return;
	}
	if (buttonPressed == btnLast){
		displayLast();
		return;
	}
	display();
}

} // end class GUI



View Postpbl, on 21 Jun, 2008 - 01:07 PM, said:

View Postsmithgang1994, on 21 Jun, 2008 - 01:05 PM, said:

when i took it out i got an error for my display under the first button


Which type of error ?

Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 01:33 PM

View Postsmithgang1994, on 21 Jun, 2008 - 01:16 PM, said:

I have to create more buttons. If I am correct I just add them the same as before, but my then I just have to figure out how to use them :) Could you possible help me get into the right direction? I will repaste my code with my new buttons.


In your actionPerformed you will have to check for these new buttons

The delete... you will have to create a new array an copy the old one

if(pressedButton == btnDelete) {
	// create an array size 1 less then before
	DVD[] newOne = new DVD[dvd.length - 1];
	// copy back my old DVD array but not the one displayed
	int k = 0;
	for(int i = 0; i < dvd.length; i++) {
		 if(i != index) 
			newOne[k++] = dvd[i];
	}
	// have dvd to point to the new array
	dvd = newOne;
	displayNext();
	return;
}



for the add you'll to do the contrary

// array with one more element
DVD[] newOne = new DVD[dvd.length+1];
for(int i = 0; i < dvd.length; i++)
   newOne[i] = dvd[i];
// then add the new one as the last one
newOne[newOne.length-1] = new DVD(info from textfield1, info from textfield2, ..........
// have dvd to point to the new one
dvd = newOne;
displayLast();
return;



the update/modify

dvd[index].quantity = from textField1
dvd[index].item = from textField2
....
dvd[index]
Was This Post Helpful? 0
  • +
  • -

#12 smithgang1994  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 30-May 08

Re: Getting my Calculate total inventory into my GUI

Posted 21 June 2008 - 02:06 PM

okay..lets see when i get to the part on add I get a cannot find symbol for the tfx... eventhough that is what i used in my code. Or am I just suppse to say textfield1?

if (buttonPressed == btnAdd){
	DVD[] newOne = new DVD[dvd.length+1];
	for(int i = 0; i< dvd.length; i++)
	newOne[i] = dvd[i];
	newOne[newOne.length-1] = new DVD( tfxVideo, tfxRating, tfxitmNumber, tfxStock, tfxPrice);
	dvd = newOne;
	displayLast();
	return;
}


View Postpbl, on 21 Jun, 2008 - 01:33 PM, said:

View Postsmithgang1994, on 21 Jun, 2008 - 01:16 PM, said:

I have to create more buttons. If I am correct I just add them the same as before, but my then I just have to figure out how to use them :) Could you possible help me get into the right direction? I will repaste my code with my new buttons.


In your actionPerformed you will have to check for these new buttons

The delete... you will have to create a new array an copy the old one

if(pressedButton == btnDelete) {
	// create an array size 1 less then before
	DVD[] newOne = new DVD[dvd.length - 1];
	// copy back my old DVD array but not the one displayed
	int k = 0;
	for(int i = 0; i < dvd.length; i++) {
		 if(i != index) 
			newOne[k++] = dvd[i];
	}
	// have dvd to point to the new array
	dvd = newOne;
	displayNext();
	return;
}



for the add you'll to do the contrary

// array with one more element
DVD[] newOne = new DVD[dvd.length+1];
for(int i = 0; i < dvd.length; i++)
   newOne[i] = dvd[i];
// then add the new one as the last one
newOne[newOne.length-1] = new DVD(info from textfield1, info from textfield2, ..........
// have dvd to point to the new one
dvd = newOne;
displayLast();
return;



the update/modify

dvd[index].quantity = from textField1
dvd[index].item = from textField2
....
dvd[index]

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1