Inventory Program part 6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mistb2002
    New Member
    • May 2007
    • 11

    Inventory Program part 6

    I am trying to modify my program to add and delete inventory items. I tried just adding but I am getting mutliple errors help.

    This is what my program currently looks like
    [code=java]
    // Display The DVDs.
    import java.text.*;
    import java.util.*;

    import java.awt.*;
    import java.awt.FlowLa yout;
    import java.awt.event. ActionListener;
    import java.awt.event. ActionEvent;
    import javax.swing.JFr ame;
    import javax.swing.JBu tton;
    import javax.swing.JTe xtField;
    import javax.swing.Ico n;
    import javax.swing.Ima geIcon;
    import javax.swing.JOp tionPane;
    import javax.swing.*;


    public class ButtonFrame extends JFrame
    {

    private JButton nextJButton; // button with just text
    private JButton prevJButton; // button with icons
    private JButton lastJButton; // button with just text
    private JButton firstJButton; // button with icons
    private JButton addJButton;// button with icons
    private JButton deleteJButton; // button with icons
    private JLabel logoLabel;
    private JTextField space1;
    private JTextField space2;
    private JTextField lblArtist; // text field with set size
    private JTextField txtArtist; // text field constructed with text
    private JTextField lblItemNum; // text field with set size
    private JTextField txtItemNum; // text field constructed with text
    private JTextField lblTitle; // text field with set size
    private JTextField txtTitle; // text field constructed with text
    private JTextField lblQuantity; // text field with set size
    private JTextField txtQuantity; // text field constructed with text
    private JTextField lblUnitPrice; // text field with set size
    private JTextField txtUnitPrice; // text field constructed with text
    private JTextField lblRestockFee; // text field with set size
    private JTextField txtRestockFee; // text field constructed with text
    private JTextField lblItemValue; // text field with set size
    private JTextField txtItemValue; // text field constructed with text
    private JTextField lblInventoryVal ue; // text field with set size
    private JTextField txtInventoryVal ue; // text field constructed with text


    // Just keeping an a class variable to keep count of where I am in the array
    // keeping a class variable of the myPlayer array that I passed
    UsedDVD[] arrayDVDs;
    private int currentArrayCou nter;
    private int arrayCount;
    private String invTotal;
    // public Image i;


    // i = getImage(getDoc umentBase(), "logo.gif") ;

    // ButtonFrame adds JButtons to JFrame
    public ButtonFrame(Use dDVD[] myDVDs, int totalArrayCount , String stringInventory Total)
    {

    super( "UsedDVD Inventory" );
    arrayDVDs = myDVDs;
    invTotal=string InventoryTotal;
    // drawImage(i,0,0 );

    // I am setting the local passed variable totalArrayCount
    // to the class variable arrayCounter so I can see it in the setTextfields method
    arrayCount = totalArrayCount ;
    currentArrayCou nter = 0;
    // Sertting the current array position to 0


    setLayout( new FlowLayout() ); // set frame layout
    // Load the next and previous icons
    Icon logo = new ImageIcon( getClass().getR esource( "logo.gif" ) );
    Icon iconNext = new ImageIcon( getClass().getR esource( "forward.gi f" ) );
    Icon iconNext = new ImageIcon( getClass().getR esource( "forward.gi f" ) );

    Icon iconNext = new ImageIcon( getClass().getR esource( "forward.gi f" ) );
    Icon iconPrev = new ImageIcon( getClass().getR esource( "back.gif" ) );
    Icon iconLast = new ImageIcon( getClass().getR esource( "last.gif" ) );
    Icon iconFirst = new ImageIcon( getClass().getR esource( "first.gif" ) );
    logoLabel = new JLabel("",logo, SwingConstants. LEFT);
    add(logoLabel);
    // construct Label Fields with default text and 25 columns
    space1 = new JTextField( "", 20 );
    space1.setEdita ble( false ); // disable editing
    add( space1 );
    space2 = new JTextField( "", 20 );
    space2.setEdita ble( false ); // disable editing
    add( space2 );
    lblItemNum = new JTextField( "Item Number", 25 );
    lblItemNum.setE ditable( false ); // disable editing
    add( lblItemNum );
    txtItemNum = new JTextField("", 25 );
    add( txtItemNum ); // add txtActor to JFrame
    lblArtist = new JTextField( "Actor", 25 );
    lblArtist.setEd itable( false ); // disable editing
    add( lblArtist );
    txtArtist = new JTextField("", 25 );
    add( txtArtist ); // add txtActor to JFrame
    lblTitle = new JTextField( "Title", 25 );
    lblTitle.setEdi table( false ); // disable editing
    add( lblTitle );
    txtTitle = new JTextField("", 25 );
    add( txtTitle ); // add txtActor to JFrame
    lblQuantity = new JTextField( "Quantity", 25 );
    lblQuantity.set Editable( false ); // disable editing
    add( lblQuantity );
    txtQuantity = new JTextField("", 25 );
    add( txtQuantity ); // add txtActor to JFrame
    lblUnitPrice = new JTextField( "Unit Price", 25 );
    lblUnitPrice.se tEditable( false ); // disable editing
    add( lblUnitPrice );
    txtUnitPrice = new JTextField("", 25 );
    add( txtUnitPrice ); // add txtUnitPrice to JFrame
    lblRestockFee = new JTextField( "Restocking Fee", 25 );
    lblRestockFee.s etEditable( false ); // disable editing
    add( lblRestockFee );
    txtRestockFee = new JTextField("", 25 );
    add( txtRestockFee ); // add txtActor to JFrame
    lblItemValue = new JTextField( "Total Item Value", 25 );
    lblItemValue.se tEditable( false ); // disable editing
    add( lblItemValue );
    txtItemValue = new JTextField("", 25 );
    add( txtItemValue ); // add txtActor to JFrame
    lblInventoryVal ue = new JTextField( "Total Inventory Value", 25 );
    lblInventoryVal ue.setEditable( false ); // disable editing
    add( lblInventoryVal ue );
    txtInventoryVal ue = new JTextField(invT otal, 25 );
    add( txtInventoryVal ue ); // add txtActor to JFrame
    // construct textfield with default text

    // Create the buttons
    nextJButton = new JButton( "Next", iconNext ); // button with Next
    prevJButton =new JButton( "Prev" , iconPrev ); // button with Next
    lastJButton = new JButton( "Last", iconLast ); // button with Next
    firstJButton =new JButton( "First" , iconFirst ); // button with Next
    add( firstJButton ); // add plainJButton to JFrame
    add(prevJButton );
    add( nextJButton ); // add plainJButton to JFrame
    add(lastJButton );
    // create new ButtonHandler for button event handling
    ButtonHandler handler = new ButtonHandler() ;
    firstJButton.ad dActionListener ( handler );
    prevJButton.add ActionListener( handler );
    nextJButton.add ActionListener( handler );
    lastJButton.add ActionListener( handler );



    // Now I am going to call SetTextFields to set the text fields
    setTextFields() ;

    } // end ButtonFrame constructor





    // inner class for button event handling
    private class ButtonHandler implements ActionListener
    {
    // handle button event
    public void actionPerformed ( ActionEvent event )
    {

    // System.out.prin tln(event.getAc tionCommand());

    // See which button was pressed
    if (event.getActio nCommand()== "Next"){


    currentArrayCou nter++;
    }
    else if (event.getActio nCommand()== "Prev"){
    currentArrayCou nter--;
    }
    else if (event.getActio nCommand()== "Last"){
    currentArrayCou nter= arrayCount-1;
    }
    else if (event.getActio nCommand()== "First"){
    currentArrayCou nter = 0;
    }

    setTextFields() ;

    } // end method actionPerformed
    } // end private inner class ButtonHandler



    private void setTextFields ()
    {
    // Make sure you havent gone past the end of the array
    if (currentArrayCo unter == arrayCount)
    {
    currentArrayCou nter = 0;
    }

    // Make sure you havent gone past the first if so, set it to the last
    if (currentArrayCo unter < 0)
    {
    currentArrayCou nter = arrayCount-1;
    }

    // System.out.prin tln(currentArra yCounter); // Debug statement

    NumberFormat n = NumberFormat.ge tCurrencyInstan ce(Locale.US); //Provides Locale appropriate currency format

    txtArtist.setTe xt(arrayDVDs[currentArrayCou nter].getactor());
    txtItemNum.setT ext(arrayDVDs[currentArrayCou nter].getitemnumber( ));
    txtTitle.setTex t(arrayDVDs[currentArrayCou nter].gettitle());
    txtQuantity.set Text(Double.toS tring(arrayDVDs[currentArrayCou nter].getquantity()) );
    txtUnitPrice.se tText(Double.to String(arrayDVD s[currentArrayCou nter].getunitprice() ));
    String stringRestockFe e = n.format(arrayD VDs[currentArrayCou nter].CalculateResto ckFee());
    txtRestockFee.s etText(stringRe stockFee);
    txtItemValue.se tText(n.format( arrayDVDs[currentArrayCou nter].calculateDVDVa lue()));


    }


    } // end class ButtonFrame[/code]
    Last edited by JosAH; May 28 '07, 03:08 PM. Reason: added [code] ... [/code] tags
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by mistb2002
    I am trying to modify my program to add and delete inventory items. I tried just adding but I am getting mutliple errors help.
    We're not here to find your errors and you're not here to play hide-'n-seek. When
    you find errors, whether they are compiler errors or runtime errors you should at
    least supply as much information as possible, and not post more than 200 lines
    of code without anything to guide your reading audience where the problem
    might be.

    Compiler errors and warning diagnostics display a nice line and column number
    indicating *where* the compilation failed, together with a friendly error message.
    Runtime errors try to do the same, together with a nice stack backtrace.

    Please try again if you want a sensible answer and only supply the relevant
    snippets of code, not long listings of wallpaper because nobody is going to read
    all that for you and seek where the error might be hiding.

    kind regards,

    Jos

    Comment

    • mistb2002
      New Member
      • May 2007
      • 11

      #3
      What a nice way of putting things ! :( I will recompile and give you the error brb

      Comment

      • mistb2002
        New Member
        • May 2007
        • 11

        #4
        Okay I am trying to write the program to allow user input for a dvd database.

        I am trying to create prompt that once add is selected another field opens allowing user input. so far I have the icon for add but I cannot develop the code for this

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by mistb2002
          Okay I am trying to write the program to allow user input for a dvd database.

          I am trying to create prompt that once add is selected another field opens allowing user input. so far I have the icon for add but I cannot develop the code for this
          Don't do it that way: first develop a method that can add a new DVD to your
          set (database or whatever) of DVDs; all necessary values are supplied to that
          method. If that works turn back to those JComponents again were a user can
          supply those necessary values in nice JTextFields or whatever.

          Decoupling the business logic (that 'addDVD' method, see above) from the view
          is a first step towards a nice MVC pattern design. Think of it this was: your DVD
          model doesn't care where those parameter values come from, as long as they
          are correct. Your controller software doesn't care how those parameters were
          obtained but check for their correctness. The view doesn't know what it's doing,
          i.e. it just allows the user to enter values and pass them on to the controller.

          kind regards,

          Jos

          Comment

          • mistb2002
            New Member
            • May 2007
            • 11

            #6
            I apologized I was too impatient and went to another post for help I am new to this and I thank you. I am taking a deserve break to eat and will resume in 1 hour. noone ever told me java was going to be this hard.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by mistb2002
              I apologized I was too impatient and went to another post for help I am new to this and I thank you. I am taking a deserve break to eat and will resume in 1 hour. noone ever told me java was going to be this hard.
              No harm done ;-) It's not Java that is the hard part; it's the entire concept of
              programming in an object oriented way; as a matter of fact, Java even flattens
              the steep learning curve if you compare it to, say, C++.

              kind regards,

              Jos

              Comment

              • mistb2002
                New Member
                • May 2007
                • 11

                #8
                I finaly got it I was on the right track by adding the JButtons for delete and add but now when I am running the program it is doing the opposite the delete is adding and the adding is deleting. look this is my ButtonFrame:
                // Display The CDs.
                import java.text.*;
                import java.util.*;

                import java.awt.*;
                import java.awt.FlowLa yout;
                import java.awt.event. ActionListener;
                import java.awt.event. ActionEvent;
                import javax.swing.JFr ame;
                import javax.swing.JBu tton;
                import javax.swing.JTe xtField;
                import javax.swing.Ico n;
                import javax.swing.Ima geIcon;
                import javax.swing.JOp tionPane;
                import javax.swing.*;


                public class ButtonFrame extends JFrame
                {
                private JButton nextJButton; // button with just text
                private JButton prevJButton; // button with icons
                private JButton lastJButton; // button with just text
                private JButton firstJButton; // button with icons
                private JButton deleteJButton; // button with icons
                private JButton addJButton; // button with icons


                private JLabel logoLabel;
                private JTextField space1;
                private JTextField space2;
                private JTextField lblActor; // text field with set size
                private JTextField txtActor; // text field constructed with text
                private JTextField lblItemNum; // text field with set size
                private JTextField txtItemNum; // text field constructed with text
                private JTextField lblTitle; // text field with set size
                private JTextField txtTitle; // text field constructed with text
                private JTextField lblQuantity; // text field with set size
                private JTextField txtQuantity; // text field constructed with text
                private JTextField lblUnitPrice; // text field with set size
                private JTextField txtUnitPrice; // text field constructed with text
                private JTextField lblRestockFee; // text field with set size
                private JTextField txtRestockFee; // text field constructed with text
                private JTextField lblItemValue; // text field with set size
                private JTextField txtItemValue; // text field constructed with text
                private JTextField lblInventoryVal ue; // text field with set size
                private JTextField txtInventoryVal ue; // text field constructed with text


                // Just keeping an a class variable to keep count of where I am in the array
                // keeping a class variable of the myPlayer array that I passed
                UsedDVD[] arrayDVDs;
                private int currentArrayCou nter;
                private int arrayCount;
                private String invTotal;
                // public Image i;


                // i = getImage(getDoc umentBase(), "logo.gif") ;

                // ButtonFrame adds JButtons to JFrame
                public ButtonFrame(Use dDVD[] myDVDs, int totalArrayCount , String stringInventory Total)
                {

                super( "UsedDVD Inventory" );
                arrayDVDs = myDVDs;
                invTotal=string InventoryTotal;
                // drawImage(i,0,0 );

                // I am setting the local passed variable totalArrayCount
                // to the class variable arrayCounter so I can see it in the setTextfields method
                arrayCount = totalArrayCount ;
                currentArrayCou nter = 0;
                // Sertting the current array position to 0


                setLayout( new FlowLayout() ); // set frame layout
                // Load the next and previous icons
                Icon logo = new ImageIcon( getClass().getR esource( "logo.gif" ) );
                Icon iconAdd = new ImageIcon( getClass().getR esource( "add.gif" ) );
                Icon iconNext = new ImageIcon( getClass().getR esource( "forward.gi f" ) );
                Icon iconPrev = new ImageIcon( getClass().getR esource( "back.gif" ) );
                Icon iconLast = new ImageIcon( getClass().getR esource( "last.gif" ) );
                Icon iconFirst = new ImageIcon( getClass().getR esource( "first.gif" ) );
                Icon iconDelete = new ImageIcon( getClass().getR esource( "Delete.gif " ) );



                logoLabel = new JLabel("",logo, SwingConstants. LEFT);
                add(logoLabel);



                // construct Label Fields with default text and 25 columns
                space1 = new JTextField( "", 20 );
                space1.setEdita ble( false ); // disable editing
                add( space1 );
                space2 = new JTextField( "", 20 );
                space2.setEdita ble( false ); // disable editing
                add( space2 );
                lblItemNum = new JTextField( "Item Number", 25 );
                lblItemNum.setE ditable( false ); // disable editing
                add( lblItemNum );
                txtItemNum = new JTextField("", 25 );
                add( txtItemNum ); // add txtActor to JFrame
                lblActor = new JTextField( "Actor ", 25 );
                lblActor.setEdi table( false ); // disable editing
                add( lblActor );
                txtActor = new JTextField("", 25 );
                add( txtActor ); // add txtActor to JFrame
                lblTitle = new JTextField( "Title", 25 );
                lblTitle.setEdi table( false ); // disable editing
                add( lblTitle );
                txtTitle = new JTextField("", 25 );
                add( txtTitle ); // add txtActor to JFrame
                lblQuantity = new JTextField( "Quantity", 25 );
                lblQuantity.set Editable( false ); // disable editing
                add( lblQuantity );
                txtQuantity = new JTextField("", 25 );
                add( txtQuantity ); // add txtActor to JFrame
                lblUnitPrice = new JTextField( "Unit Price", 25 );
                lblUnitPrice.se tEditable( false ); // disable editing
                add( lblUnitPrice );
                txtUnitPrice = new JTextField("", 25 );
                add( txtUnitPrice ); // add txtUnitPrice to JFrame
                lblRestockFee = new JTextField( "Restocking Fee", 25 );
                lblRestockFee.s etEditable( false ); // disable editing
                add( lblRestockFee );
                txtRestockFee = new JTextField("", 25 );
                add( txtRestockFee ); // add txtActor to JFrame
                lblItemValue = new JTextField( "Total Item Value", 25 );
                lblItemValue.se tEditable( false ); // disable editing
                add( lblItemValue );
                txtItemValue = new JTextField("", 25 );
                add( txtItemValue ); // add txtActor to JFrame
                lblInventoryVal ue = new JTextField( "Total Inventory Value", 25 );
                lblInventoryVal ue.setEditable( false ); // disable editing
                add( lblInventoryVal ue );
                txtInventoryVal ue = new JTextField(invT otal, 25 );
                add( txtInventoryVal ue ); // add txtActor to JFrame
                // construct textfield with default text

                // Create the buttons
                nextJButton = new JButton( "Next", iconNext ); // button with Next
                prevJButton =new JButton( "Prev" , iconPrev ); // button with Prev
                lastJButton = new JButton( "Last", iconLast ); // button with Last
                firstJButton =new JButton( "First" , iconFirst ); // button with First
                deleteJButton = new JButton("Delete ",iconDelet e);
                addJButton = new JButton ( "Add",iconA dd);

                add( addJButton );
                add( firstJButton ); // add plainJButton to JFrame
                add(prevJButton );
                add( nextJButton ); // add plainJButton to JFrame
                add(lastJButton );
                add(deleteJButt on);



                // create new ButtonHandler for button event handling
                ButtonHandler handler = new ButtonHandler() ;
                addJButton.addA ctionListener ( handler );
                firstJButton.ad dActionListener ( handler );
                prevJButton.add ActionListener( handler );
                nextJButton.add ActionListener( handler );
                lastJButton.add ActionListener( handler );
                deleteJButton.a ddActionListene r( handler );


                // Now I am going to call SetTextFields to set the text fields
                setTextFields() ;

                } // end ButtonFrame constructor





                // inner class for button event handling
                private class ButtonHandler implements ActionListener
                {
                // handle button event
                public void actionPerformed ( ActionEvent event )
                {

                System.out.prin tln("In Action Command - Current Event is " + event.getAction Command());

                // See which button was pressed
                if (event.getActio nCommand()== "Next"){


                currentArrayCou nter++;
                }
                else if (event.getActio nCommand()== "Prev"){
                currentArrayCou nter--;
                }
                else if (event.getActio nCommand()== "Last"){
                currentArrayCou nter= arrayCount-1;
                }
                else if (event.getActio nCommand()== "First"){
                currentArrayCou nter = 0;
                }
                else if (event.getActio nCommand()== "Add"){
                arrayDVDs[currentArrayCou nter=1].addToQuantity( );

                }

                else if (event.getActio nCommand()== "Delete"){
                arrayDVDs[currentArrayCou nter].removeOneFromQ uantity();
                System.out.prin tln("Deleting") ;
                }







                setTextFields() ;

                } // end method actionPerformed
                } // end private inner class ButtonHandler



                private void setTextFields ()
                {
                // This is to ensure that you are not at the end of the array
                if (currentArrayCo unter == arrayCount)
                {
                currentArrayCou nter = 0;
                }

                // This is set to prevent from going past the first if so I am setting it to the last
                if (currentArrayCo unter < 0)
                {
                currentArrayCou nter = arrayCount-1;
                }

                // System.out.prin tln(currentArra yCounter); // Debug statement

                NumberFormat n = NumberFormat.ge tCurrencyInstan ce(Locale.US); //Provides Locale appropriate currency format

                txtActor.setTex t(arrayDVDs[currentArrayCou nter].getactor());
                txtItemNum.setT ext(arrayDVDs[currentArrayCou nter].getitemnumber( ));
                txtTitle.setTex t(arrayDVDs[currentArrayCou nter].gettitle());
                txtQuantity.set Text(Double.toS tring(arrayDVDs[currentArrayCou nter].getquantity()) );
                txtUnitPrice.se tText(Double.to String(arrayDVD s[currentArrayCou nter].getunitprice() ));
                String stringRestockFe e = n.format(arrayD VDs[currentArrayCou nter].CalculateResto ckFee());
                txtRestockFee.s etText(stringRe stockFee);
                txtItemValue.se tText(n.format( arrayDVDs[currentArrayCou nter].calculateDVDVa lue()));


                }


                } // end class ButtonFrame


                [B]what am i doing wrong?

                Comment

                • mistb2002
                  New Member
                  • May 2007
                  • 11

                  #9
                  I enjoy breaking and fixing a pc rather than programming. programming keeps me up all hours of the night. I'm starting to eat drink and sleep JAVA[ mainly how to improve my program] The first thing I did when I came home was hit the pc to work on my program, I did not even greet my daughter. this is baaaad!

                  Comment

                  • nomad
                    Recognized Expert Contributor
                    • Mar 2007
                    • 664

                    #10
                    Originally posted by mistb2002
                    I enjoy breaking and fixing a pc rather than programming. programming keeps me up all hours of the night. I'm starting to eat drink and sleep JAVA[ mainly how to improve my program] The first thing I did when I came home was hit the pc to work on my program, I did not even greet my daughter. this is baaaad!
                    Hey that how I feel I'm starting to eat, drink and sleep JAVA. I wake up think about java, infact I try to help other in Java either here on thescripts or Java main tech forum. I even started writing a article of Arraylist in which Jos talked me into and I still have to finish it, and I just took one course...
                    good grief...
                    JAVA Java java, my wife is calling me. Good night....

                    Comment

                    • mistb2002
                      New Member
                      • May 2007
                      • 11

                      #11
                      I cannot get this program to add can you take a look?


                      This is the button frame

                      // Display The CDs.
                      import java.text.*;
                      import java.util.*;

                      import java.awt.*;
                      import java.awt.FlowLa yout;
                      import java.awt.event. ActionListener;
                      import java.awt.event. ActionEvent;
                      import javax.swing.JFr ame;
                      import javax.swing.JBu tton;
                      import javax.swing.JTe xtField;
                      import javax.swing.Ico n;
                      import javax.swing.Ima geIcon;
                      import javax.swing.JOp tionPane;
                      import javax.swing.*;


                      public class ButtonFrame extends JFrame
                      {
                      private JButton nextJButton; // button with just text
                      private JButton prevJButton; // button with icons
                      private JButton lastJButton; // button with just text
                      private JButton firstJButton; // button with icons
                      private JButton deleteJButton; // button with icons
                      private JButton addJButton; // button with icons


                      private JLabel logoLabel;
                      private JTextField space1;
                      private JTextField space2;
                      private JTextField lblActor; // text field with set size
                      private JTextField txtActor; // text field constructed with text
                      private JTextField lblItemNum; // text field with set size
                      private JTextField txtItemNum; // text field constructed with text
                      private JTextField lblTitle; // text field with set size
                      private JTextField txtTitle; // text field constructed with text
                      private JTextField lblQuantity; // text field with set size
                      private JTextField txtQuantity; // text field constructed with text
                      private JTextField lblUnitPrice; // text field with set size
                      private JTextField txtUnitPrice; // text field constructed with text
                      private JTextField lblRestockFee; // text field with set size
                      private JTextField txtRestockFee; // text field constructed with text
                      private JTextField lblItemValue; // text field with set size
                      private JTextField txtItemValue; // text field constructed with text
                      private JTextField lblInventoryVal ue; // text field with set size
                      private JTextField txtInventoryVal ue; // text field constructed with text


                      // Just keeping an a class variable to keep count of where I am in the array
                      // keeping a class variable of the myPlayer array that I passed
                      UsedDVD[] arrayDVDs;
                      private int currentArrayCou nter;
                      private int arrayCount;
                      private String invTotal;
                      // public Image i;


                      // i = getImage(getDoc umentBase(), "logo.gif") ;

                      // ButtonFrame adds JButtons to JFrame
                      public ButtonFrame(Use dDVD[] myDVDs, int totalArrayCount , String stringInventory Total)
                      {

                      super( "UsedDVD Inventory" );
                      arrayDVDs = myDVDs;
                      invTotal=string InventoryTotal;
                      // drawImage(i,0,0 );

                      // I am setting the local passed variable totalArrayCount
                      // to the class variable arrayCounter so I can see it in the setTextfields method
                      arrayCount = totalArrayCount ;
                      currentArrayCou nter = 0;
                      // Sertting the current array position to 0


                      setLayout( new FlowLayout() ); // set frame layout
                      // Load the next and previous icons
                      Icon logo = new ImageIcon( getClass().getR esource( "logo.gif" ) );
                      Icon iconAdd = new ImageIcon( getClass().getR esource( "add.gif" ) );
                      Icon iconNext = new ImageIcon( getClass().getR esource( "forward.gi f" ) );
                      Icon iconPrev = new ImageIcon( getClass().getR esource( "back.gif" ) );
                      Icon iconLast = new ImageIcon( getClass().getR esource( "last.gif" ) );
                      Icon iconFirst = new ImageIcon( getClass().getR esource( "first.gif" ) );
                      Icon iconDelete = new ImageIcon( getClass().getR esource( "Delete.gif " ) );



                      logoLabel = new JLabel("",logo, SwingConstants. LEFT);
                      add(logoLabel);



                      // construct Label Fields with default text and 25 columns
                      space1 = new JTextField( "", 20 );
                      space1.setEdita ble( false ); // disable editing
                      add( space1 );
                      space2 = new JTextField( "", 20 );
                      space2.setEdita ble( false ); // disable editing
                      add( space2 );
                      lblItemNum = new JTextField( "Item Number", 25 );
                      lblItemNum.setE ditable( false ); // disable editing
                      add( lblItemNum );
                      txtItemNum = new JTextField("", 25 );
                      add( txtItemNum ); // add txtActor to JFrame
                      lblActor = new JTextField( "Actor ", 25 );
                      lblActor.setEdi table( false ); // disable editing
                      add( lblActor );
                      txtActor = new JTextField("", 25 );
                      add( txtActor ); // add txtActor to JFrame
                      lblTitle = new JTextField( "Title", 25 );
                      lblTitle.setEdi table( false ); // disable editing
                      add( lblTitle );
                      txtTitle = new JTextField("", 25 );
                      add( txtTitle ); // add txtActor to JFrame
                      lblQuantity = new JTextField( "Quantity", 25 );
                      lblQuantity.set Editable( false ); // disable editing
                      add( lblQuantity );
                      txtQuantity = new JTextField("", 25 );
                      add( txtQuantity ); // add txtActor to JFrame
                      lblUnitPrice = new JTextField( "Unit Price", 25 );
                      lblUnitPrice.se tEditable( false ); // disable editing
                      add( lblUnitPrice );
                      txtUnitPrice = new JTextField("", 25 );
                      add( txtUnitPrice ); // add txtUnitPrice to JFrame
                      lblRestockFee = new JTextField( "Restocking Fee", 25 );
                      lblRestockFee.s etEditable( false ); // disable editing
                      add( lblRestockFee );
                      txtRestockFee = new JTextField("", 25 );
                      add( txtRestockFee ); // add txtActor to JFrame
                      lblItemValue = new JTextField( "Total Item Value", 25 );
                      lblItemValue.se tEditable( false ); // disable editing
                      add( lblItemValue );
                      txtItemValue = new JTextField("", 25 );
                      add( txtItemValue ); // add txtActor to JFrame
                      lblInventoryVal ue = new JTextField( "Total Inventory Value", 25 );
                      lblInventoryVal ue.setEditable( false ); // disable editing
                      add( lblInventoryVal ue );
                      txtInventoryVal ue = new JTextField(invT otal, 25 );
                      add( txtInventoryVal ue ); // add txtActor to JFrame
                      // construct textfield with default text

                      // Create the buttons
                      nextJButton = new JButton( "Next", iconNext ); // button with Next
                      prevJButton =new JButton( "Prev" , iconPrev ); // button with Prev
                      lastJButton = new JButton( "Last", iconLast ); // button with Last
                      firstJButton =new JButton( "First" , iconFirst ); // button with First
                      deleteJButton = new JButton("Delete ",iconDelet e);
                      addJButton = new JButton ( "Add",iconA dd);

                      add( addJButton );
                      add( firstJButton ); // add plainJButton to JFrame
                      add(prevJButton );
                      add( nextJButton ); // add plainJButton to JFrame
                      add(lastJButton );
                      add(deleteJButt on);



                      // create new ButtonHandler for button event handling
                      ButtonHandler handler = new ButtonHandler() ;
                      addJButton.addA ctionListener ( handler );
                      firstJButton.ad dActionListener ( handler );
                      prevJButton.add ActionListener( handler );
                      nextJButton.add ActionListener( handler );
                      lastJButton.add ActionListener( handler );
                      deleteJButton.a ddActionListene r( handler );


                      // Now I am going to call SetTextFields to set the text fields
                      setTextFields() ;

                      } // end ButtonFrame constructor





                      // inner class for button event handling
                      private class ButtonHandler implements ActionListener
                      {
                      // handle button event
                      public void actionPerformed ( ActionEvent event )
                      {

                      System.out.prin tln("In Action Command - Current Event is " + event.getAction Command());

                      // See which button was pressed
                      if (event.getActio nCommand()== "Next"){


                      currentArrayCou nter++;
                      }
                      else if (event.getActio nCommand()== "Prev"){
                      currentArrayCou nter--;
                      }
                      else if (event.getActio nCommand()== "Last"){
                      currentArrayCou nter= arrayCount-1;
                      }
                      else if (event.getActio nCommand()== "First"){
                      currentArrayCou nter = 0;
                      }
                      else if (event.getActio nCommand()== "Add"){
                      currentArrayCou nter=arrayCount +1;
                      }
                      else if (event.getActio nCommand()== "Add"){
                      arrayDVDs[currentArrayCou nter].addOneToQuanti ty();
                      System.out.prin tln("Adding");
                      }
                      else if (event.getActio nCommand()== "Delete"){
                      arrayDVDs[currentArrayCou nter].removeOneFromQ uantity();
                      System.out.prin tln("Deleting") ;
                      }







                      setTextFields() ;

                      } // end method actionPerformed
                      } // end private inner class ButtonHandler



                      private void setTextFields ()
                      {
                      // This is to ensure that you are not at the end of the array
                      if (currentArrayCo unter == arrayCount)
                      {
                      currentArrayCou nter = 0;
                      }

                      // This is set to prevent from going past the first if so I am setting it to the last
                      if (currentArrayCo unter < 0)
                      {
                      currentArrayCou nter = arrayCount-1;
                      }

                      // System.out.prin tln(currentArra yCounter); // Debug statement

                      NumberFormat n = NumberFormat.ge tCurrencyInstan ce(Locale.US); //Provides Locale appropriate currency format

                      txtActor.setTex t(arrayDVDs[currentArrayCou nter].getactor());
                      txtItemNum.setT ext(arrayDVDs[currentArrayCou nter].getitemnumber( ));
                      txtTitle.setTex t(arrayDVDs[currentArrayCou nter].gettitle());
                      txtQuantity.set Text(Double.toS tring(arrayDVDs[currentArrayCou nter].getquantity()) );
                      txtUnitPrice.se tText(Double.to String(arrayDVD s[currentArrayCou nter].getunitprice() ));
                      String stringRestockFe e = n.format(arrayD VDs[currentArrayCou nter].CalculateResto ckFee());
                      txtRestockFee.s etText(stringRe stockFee);
                      txtItemValue.se tText(n.format( arrayDVDs[currentArrayCou nter].calculateDVDVa lue()));


                      }


                      } // end class ButtonFrame

                      Comment

                      Working...