Welcome to Dream.In.Code
Become a Java Expert!

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!




Getting my Calculate total inventory into my GUI

 
Reply to this topicStart new topic

Getting my Calculate total inventory into my GUI

smithgang1994
21 Jun, 2008 - 10:21 AM
Post #1

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
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
{

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

CODE

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


User is offlineProfile CardPM
+Quote Post

pbl
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 10:35 AM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
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





User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 10:48 AM
Post #3

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
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 smile.gif so I can see the buttons! Well off I go...I will probably see you soon crazy.gif


User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 11:30 AM
Post #4

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


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

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

User is offlineProfile CardPM
+Quote Post

pbl
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 11:44 AM
Post #5

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Not there
must be in the DVD class... leftover that you had before you wrote this gorgeous GUI
User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 11:49 AM
Post #6

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
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

    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 tongue.gif ***
QUOTE(pbl @ 21 Jun, 2008 - 12:44 PM) *

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


User is offlineProfile CardPM
+Quote Post

pbl
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 11:57 AM
Post #7

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Sorry... by saying "display" I though you where talking about
System.out.println("Something");

Here is the culprit

CODE

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


User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 12:05 PM
Post #8

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
I need to learn to go with my instincts..i thought of doing that..but i didnt biggrin.gif

QUOTE(pbl @ 21 Jun, 2008 - 12:57 PM) *

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

Here is the culprit

CODE

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

QUOTE(pbl @ 21 Jun, 2008 - 12:57 PM) *

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

Here is the culprit

CODE

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

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 biggrin.gif

QUOTE(pbl @ 21 Jun, 2008 - 12:57 PM) *

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

Here is the culprit

CODE

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

QUOTE(pbl @ 21 Jun, 2008 - 12:57 PM) *

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

Here is the culprit

CODE

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



User is offlineProfile CardPM
+Quote Post

pbl
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 12:07 PM
Post #9

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(smithgang1994 @ 21 Jun, 2008 - 01:05 PM) *


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



Which type of error ?

User is offlineProfile CardPM
+Quote Post

smithgang1994
RE: Getting My Calculate Total Inventory Into My GUI
21 Jun, 2008 - 12:16 PM
Post #10

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
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 smile.gif 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
{

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


QUOTE(pbl @ 21 Jun, 2008 - 01:07 PM) *

QUOTE(smithgang1994 @ 21 Jun, 2008 - 01:05 PM) *


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



Which type of error ?


User is offlineProfile CardPM