Join 150,100 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,854 people online right now. Registration is fast and FREE... Join Now!
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());
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 implements ActionListener {
// 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 );
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());
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
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
// 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 );
its only gorgeous cuz you have helped me tons! here is my dvd classl
CODE
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
CODE
//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
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
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
QUOTE(pbl @ 21 Jun, 2008 - 12:57 PM)
Sorry... by saying "display" I though you where talking about System.out.println("Something");
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
QUOTE(smithgang1994 @ 21 Jun, 2008 - 01:03 PM)
I need to learn to go with my instincts..i thought of doing that..but i didnt
QUOTE(pbl @ 21 Jun, 2008 - 12:57 PM)
Sorry... by saying "display" I though you where talking about System.out.println("Something");
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
QUOTE(pbl @ 21 Jun, 2008 - 12:57 PM)
Sorry... by saying "display" I though you where talking about System.out.println("Something");
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
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.
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 implements ActionListener {
// 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 );