473,378 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1. // Display The DVDs.
  2. import java.text.*;
  3. import java.util.*;
  4.  
  5. import java.awt.*;
  6. import java.awt.FlowLayout;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ActionEvent;
  9. import javax.swing.JFrame;
  10. import javax.swing.JButton;
  11. import javax.swing.JTextField;
  12. import javax.swing.Icon;
  13. import javax.swing.ImageIcon;
  14. import javax.swing.JOptionPane;
  15. import javax.swing.*;
  16.  
  17.  
  18. public class ButtonFrame extends JFrame
  19. {
  20.  
  21.    private JButton nextJButton; // button with just text
  22.    private JButton prevJButton; // button with icons
  23.    private JButton lastJButton; // button with just text
  24.    private JButton firstJButton; // button with icons
  25.    private JButton addJButton;// button with icons
  26.    private JButton deleteJButton; // button with icons
  27.    private JLabel logoLabel;
  28.    private JTextField space1;
  29.    private JTextField space2;
  30.    private JTextField lblArtist; // text field with set size
  31.    private JTextField txtArtist; // text field constructed with text
  32.    private JTextField lblItemNum; // text field with set size
  33.    private JTextField txtItemNum; // text field constructed with text
  34.    private JTextField lblTitle; // text field with set size
  35.    private JTextField txtTitle; // text field constructed with text
  36.    private JTextField lblQuantity; // text field with set size
  37.    private JTextField txtQuantity; // text field constructed with text
  38.    private JTextField lblUnitPrice; // text field with set size
  39.    private JTextField txtUnitPrice; // text field constructed with text
  40.    private JTextField lblRestockFee; // text field with set size
  41.    private JTextField txtRestockFee; // text field constructed with text
  42.    private JTextField lblItemValue; // text field with set size
  43.    private JTextField txtItemValue; // text field constructed with text
  44.    private JTextField lblInventoryValue; // text field with set size
  45.    private JTextField txtInventoryValue; // text field constructed with text
  46.  
  47.  
  48.   // Just keeping an a class variable to keep count of where I am in the array
  49.   //  keeping a class variable of the myPlayer array that I passed
  50.   UsedDVD[] arrayDVDs;
  51.   private int currentArrayCounter;
  52.   private int arrayCount;
  53.   private String invTotal;
  54.  // public Image i;
  55.  
  56.  
  57. //   i = getImage(getDocumentBase(), "logo.gif");
  58.  
  59.    // ButtonFrame adds JButtons to JFrame
  60.    public ButtonFrame(UsedDVD[] myDVDs, int totalArrayCount, String stringInventoryTotal)
  61.    {
  62.  
  63.       super( "UsedDVD Inventory" );
  64.       arrayDVDs = myDVDs;
  65.       invTotal=stringInventoryTotal;
  66. //      drawImage(i,0,0);
  67.  
  68.       // I am setting the local passed variable totalArrayCount
  69.       // to the class variable arrayCounter so I can see it in the setTextfields method
  70.       arrayCount = totalArrayCount;
  71.       currentArrayCounter = 0;
  72.       // Sertting the current array position to 0
  73.  
  74.  
  75.       setLayout( new FlowLayout() ); // set frame layout
  76.      // Load the next and previous icons
  77.       Icon logo = new ImageIcon( getClass().getResource( "logo.gif" ) );
  78.       Icon iconNext = new ImageIcon( getClass().getResource( "forward.gif" ) );
  79. Icon iconNext = new ImageIcon( getClass().getResource( "forward.gif" ) );
  80.  
  81.       Icon iconNext = new ImageIcon( getClass().getResource( "forward.gif" ) );
  82.       Icon iconPrev = new ImageIcon( getClass().getResource( "back.gif" ) );
  83.       Icon iconLast = new ImageIcon( getClass().getResource( "last.gif" ) );
  84.       Icon iconFirst = new ImageIcon( getClass().getResource( "first.gif" ) );
  85.       logoLabel = new JLabel("",logo,SwingConstants.LEFT);
  86.       add(logoLabel);
  87.       // construct Label Fields with default text and 25 columns
  88.       space1 = new JTextField( "", 20 );
  89.       space1.setEditable( false ); // disable editing
  90.       add( space1 );
  91.       space2 = new JTextField( "", 20 );
  92.       space2.setEditable( false ); // disable editing
  93.       add( space2 );
  94.       lblItemNum = new JTextField( "Item Number", 25 );
  95.       lblItemNum.setEditable( false ); // disable editing
  96.       add( lblItemNum );
  97.       txtItemNum = new JTextField("",  25 );
  98.       add( txtItemNum ); // add txtActor to JFrame
  99.       lblArtist = new JTextField( "Actor", 25 );
  100.       lblArtist.setEditable( false ); // disable editing
  101.       add( lblArtist );
  102.       txtArtist = new JTextField("",  25 );
  103.       add( txtArtist ); // add txtActor to JFrame
  104.       lblTitle = new JTextField( "Title", 25 );
  105.       lblTitle.setEditable( false ); // disable editing
  106.       add( lblTitle );
  107.       txtTitle = new JTextField("",  25 );
  108.       add( txtTitle ); // add txtActor to JFrame
  109.       lblQuantity = new JTextField( "Quantity", 25 );
  110.       lblQuantity.setEditable( false ); // disable editing
  111.       add( lblQuantity );
  112.       txtQuantity = new JTextField("",  25 );
  113.       add( txtQuantity ); // add txtActor to JFrame
  114.       lblUnitPrice = new JTextField( "Unit Price", 25 );
  115.       lblUnitPrice.setEditable( false ); // disable editing
  116.       add( lblUnitPrice );
  117.       txtUnitPrice = new JTextField("",  25 );
  118.       add( txtUnitPrice ); // add txtUnitPrice to JFrame
  119.       lblRestockFee = new JTextField( "Restocking Fee", 25 );
  120.       lblRestockFee.setEditable( false ); // disable editing
  121.       add( lblRestockFee );
  122.       txtRestockFee = new JTextField("",  25 );
  123.       add( txtRestockFee ); // add txtActor to JFrame
  124.       lblItemValue = new JTextField( "Total Item Value", 25 );
  125.       lblItemValue.setEditable( false ); // disable editing
  126.       add( lblItemValue );
  127.       txtItemValue = new JTextField("",  25 );
  128.       add( txtItemValue ); // add txtActor to JFrame
  129.       lblInventoryValue = new JTextField( "Total Inventory Value", 25 );
  130.       lblInventoryValue.setEditable( false ); // disable editing
  131.       add( lblInventoryValue );
  132.       txtInventoryValue = new JTextField(invTotal,  25 );
  133.       add( txtInventoryValue ); // add txtActor to JFrame
  134.       // construct textfield with default text
  135.  
  136.      // Create the buttons
  137.       nextJButton = new JButton( "Next", iconNext ); // button with Next
  138.       prevJButton  =new JButton( "Prev" , iconPrev ); // button with Next
  139.       lastJButton = new JButton( "Last", iconLast ); // button with Next
  140.       firstJButton  =new JButton( "First" , iconFirst ); // button with Next
  141.       add( firstJButton ); // add plainJButton to JFrame
  142.       add(prevJButton);
  143.       add( nextJButton ); // add plainJButton to JFrame
  144.       add(lastJButton);
  145.       // create new ButtonHandler for button event handling
  146.       ButtonHandler handler = new ButtonHandler();
  147.       firstJButton.addActionListener( handler );
  148.       prevJButton.addActionListener( handler );
  149.       nextJButton.addActionListener( handler );
  150.       lastJButton.addActionListener( handler );
  151.  
  152.  
  153.  
  154.       // Now I am going to call SetTextFields to set the text fields
  155.       setTextFields();
  156.  
  157.    } // end ButtonFrame constructor
  158.  
  159.  
  160.  
  161.  
  162.  
  163.    // inner class for button event handling
  164.    private class ButtonHandler implements ActionListener
  165.    {
  166.       // handle button event
  167.       public void actionPerformed( ActionEvent event )
  168.       {
  169.  
  170. //               System.out.println(event.getActionCommand());
  171.  
  172.          // See which button was pressed
  173.          if (event.getActionCommand()== "Next"){
  174.  
  175.  
  176.            currentArrayCounter++;
  177.         }
  178.        else if (event.getActionCommand()== "Prev"){
  179.         currentArrayCounter--;
  180.         }
  181.          else if (event.getActionCommand()== "Last"){
  182.            currentArrayCounter= arrayCount-1;
  183.          }
  184.            else if (event.getActionCommand()== "First"){
  185.              currentArrayCounter = 0;
  186.            }
  187.  
  188.         setTextFields();
  189.  
  190.        } // end method actionPerformed
  191.    } // end private inner class ButtonHandler
  192.  
  193.  
  194.  
  195. private void setTextFields ()
  196. {
  197.     // Make sure you havent gone past the end of the array
  198.  if (currentArrayCounter == arrayCount)
  199.  {
  200.      currentArrayCounter = 0;
  201.  }
  202.  
  203.  // Make sure you havent gone past the first  if so, set it to the last
  204.  if (currentArrayCounter < 0)
  205.   {
  206.       currentArrayCounter = arrayCount-1;
  207.  }
  208.  
  209. //      System.out.println(currentArrayCounter);  // Debug statement
  210.  
  211.     NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US);   //Provides Locale appropriate currency format
  212.  
  213.     txtArtist.setText(arrayDVDs[currentArrayCounter].getactor());
  214.     txtItemNum.setText(arrayDVDs[currentArrayCounter].getitemnumber());
  215.     txtTitle.setText(arrayDVDs[currentArrayCounter].gettitle());
  216.     txtQuantity.setText(Double.toString(arrayDVDs[currentArrayCounter].getquantity()));
  217.     txtUnitPrice.setText(Double.toString(arrayDVDs[currentArrayCounter].getunitprice()));
  218.     String stringRestockFee = n.format(arrayDVDs[currentArrayCounter].CalculateRestockFee());
  219.     txtRestockFee.setText(stringRestockFee);
  220.     txtItemValue.setText(n.format(arrayDVDs[currentArrayCounter].calculateDVDValue()));
  221.  
  222.  
  223. }
  224.  
  225.  
  226. } // end class ButtonFrame
May 28 '07 #1
10 5827
JosAH
11,448 Expert 8TB
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
May 28 '07 #2
What a nice way of putting things ! :( I will recompile and give you the error brb
May 28 '07 #3
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
May 28 '07 #4
JosAH
11,448 Expert 8TB
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
May 28 '07 #5
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.
May 28 '07 #6
JosAH
11,448 Expert 8TB
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
May 28 '07 #7
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.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
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 lblInventoryValue; // text field with set size
private JTextField txtInventoryValue; // 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 currentArrayCounter;
private int arrayCount;
private String invTotal;
// public Image i;


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

// ButtonFrame adds JButtons to JFrame
public ButtonFrame(UsedDVD[] myDVDs, int totalArrayCount, String stringInventoryTotal)
{

super( "UsedDVD Inventory" );
arrayDVDs = myDVDs;
invTotal=stringInventoryTotal;
// 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;
currentArrayCounter = 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().getResource( "logo.gif" ) );
Icon iconAdd = new ImageIcon( getClass().getResource( "add.gif" ) );
Icon iconNext = new ImageIcon( getClass().getResource( "forward.gif" ) );
Icon iconPrev = new ImageIcon( getClass().getResource( "back.gif" ) );
Icon iconLast = new ImageIcon( getClass().getResource( "last.gif" ) );
Icon iconFirst = new ImageIcon( getClass().getResource( "first.gif" ) );
Icon iconDelete = new ImageIcon( getClass().getResource( "Delete.gif" ) );



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



// construct Label Fields with default text and 25 columns
space1 = new JTextField( "", 20 );
space1.setEditable( false ); // disable editing
add( space1 );
space2 = new JTextField( "", 20 );
space2.setEditable( false ); // disable editing
add( space2 );
lblItemNum = new JTextField( "Item Number", 25 );
lblItemNum.setEditable( false ); // disable editing
add( lblItemNum );
txtItemNum = new JTextField("", 25 );
add( txtItemNum ); // add txtActor to JFrame
lblActor = new JTextField( "Actor ", 25 );
lblActor.setEditable( false ); // disable editing
add( lblActor );
txtActor = new JTextField("", 25 );
add( txtActor ); // add txtActor to JFrame
lblTitle = new JTextField( "Title", 25 );
lblTitle.setEditable( false ); // disable editing
add( lblTitle );
txtTitle = new JTextField("", 25 );
add( txtTitle ); // add txtActor to JFrame
lblQuantity = new JTextField( "Quantity", 25 );
lblQuantity.setEditable( false ); // disable editing
add( lblQuantity );
txtQuantity = new JTextField("", 25 );
add( txtQuantity ); // add txtActor to JFrame
lblUnitPrice = new JTextField( "Unit Price", 25 );
lblUnitPrice.setEditable( false ); // disable editing
add( lblUnitPrice );
txtUnitPrice = new JTextField("", 25 );
add( txtUnitPrice ); // add txtUnitPrice to JFrame
lblRestockFee = new JTextField( "Restocking Fee", 25 );
lblRestockFee.setEditable( false ); // disable editing
add( lblRestockFee );
txtRestockFee = new JTextField("", 25 );
add( txtRestockFee ); // add txtActor to JFrame
lblItemValue = new JTextField( "Total Item Value", 25 );
lblItemValue.setEditable( false ); // disable editing
add( lblItemValue );
txtItemValue = new JTextField("", 25 );
add( txtItemValue ); // add txtActor to JFrame
lblInventoryValue = new JTextField( "Total Inventory Value", 25 );
lblInventoryValue.setEditable( false ); // disable editing
add( lblInventoryValue );
txtInventoryValue = new JTextField(invTotal, 25 );
add( txtInventoryValue ); // 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",iconDelete);
addJButton = new JButton ( "Add",iconAdd);

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



// create new ButtonHandler for button event handling
ButtonHandler handler = new ButtonHandler();
addJButton.addActionListener ( handler );
firstJButton.addActionListener( handler );
prevJButton.addActionListener( handler );
nextJButton.addActionListener( handler );
lastJButton.addActionListener( handler );
deleteJButton.addActionListener( 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.println("In Action Command - Current Event is " + event.getActionCommand());

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


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

}

else if (event.getActionCommand()== "Delete"){
arrayDVDs[currentArrayCounter].removeOneFromQuantity();
System.out.println("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 (currentArrayCounter == arrayCount)
{
currentArrayCounter = 0;
}

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

// System.out.println(currentArrayCounter); // Debug statement

NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US); //Provides Locale appropriate currency format

txtActor.setText(arrayDVDs[currentArrayCounter].getactor());
txtItemNum.setText(arrayDVDs[currentArrayCounter].getitemnumber());
txtTitle.setText(arrayDVDs[currentArrayCounter].gettitle());
txtQuantity.setText(Double.toString(arrayDVDs[currentArrayCounter].getquantity()));
txtUnitPrice.setText(Double.toString(arrayDVDs[currentArrayCounter].getunitprice()));
String stringRestockFee = n.format(arrayDVDs[currentArrayCounter].CalculateRestockFee());
txtRestockFee.setText(stringRestockFee);
txtItemValue.setText(n.format(arrayDVDs[currentArrayCounter].calculateDVDValue()));


}


} // end class ButtonFrame


[b]what am i doing wrong?
May 30 '07 #8
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!
May 30 '07 #9
nomad
664 Expert 512MB
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....
May 30 '07 #10
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.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
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 lblInventoryValue; // text field with set size
private JTextField txtInventoryValue; // 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 currentArrayCounter;
private int arrayCount;
private String invTotal;
// public Image i;


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

// ButtonFrame adds JButtons to JFrame
public ButtonFrame(UsedDVD[] myDVDs, int totalArrayCount, String stringInventoryTotal)
{

super( "UsedDVD Inventory" );
arrayDVDs = myDVDs;
invTotal=stringInventoryTotal;
// 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;
currentArrayCounter = 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().getResource( "logo.gif" ) );
Icon iconAdd = new ImageIcon( getClass().getResource( "add.gif" ) );
Icon iconNext = new ImageIcon( getClass().getResource( "forward.gif" ) );
Icon iconPrev = new ImageIcon( getClass().getResource( "back.gif" ) );
Icon iconLast = new ImageIcon( getClass().getResource( "last.gif" ) );
Icon iconFirst = new ImageIcon( getClass().getResource( "first.gif" ) );
Icon iconDelete = new ImageIcon( getClass().getResource( "Delete.gif" ) );



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



// construct Label Fields with default text and 25 columns
space1 = new JTextField( "", 20 );
space1.setEditable( false ); // disable editing
add( space1 );
space2 = new JTextField( "", 20 );
space2.setEditable( false ); // disable editing
add( space2 );
lblItemNum = new JTextField( "Item Number", 25 );
lblItemNum.setEditable( false ); // disable editing
add( lblItemNum );
txtItemNum = new JTextField("", 25 );
add( txtItemNum ); // add txtActor to JFrame
lblActor = new JTextField( "Actor ", 25 );
lblActor.setEditable( false ); // disable editing
add( lblActor );
txtActor = new JTextField("", 25 );
add( txtActor ); // add txtActor to JFrame
lblTitle = new JTextField( "Title", 25 );
lblTitle.setEditable( false ); // disable editing
add( lblTitle );
txtTitle = new JTextField("", 25 );
add( txtTitle ); // add txtActor to JFrame
lblQuantity = new JTextField( "Quantity", 25 );
lblQuantity.setEditable( false ); // disable editing
add( lblQuantity );
txtQuantity = new JTextField("", 25 );
add( txtQuantity ); // add txtActor to JFrame
lblUnitPrice = new JTextField( "Unit Price", 25 );
lblUnitPrice.setEditable( false ); // disable editing
add( lblUnitPrice );
txtUnitPrice = new JTextField("", 25 );
add( txtUnitPrice ); // add txtUnitPrice to JFrame
lblRestockFee = new JTextField( "Restocking Fee", 25 );
lblRestockFee.setEditable( false ); // disable editing
add( lblRestockFee );
txtRestockFee = new JTextField("", 25 );
add( txtRestockFee ); // add txtActor to JFrame
lblItemValue = new JTextField( "Total Item Value", 25 );
lblItemValue.setEditable( false ); // disable editing
add( lblItemValue );
txtItemValue = new JTextField("", 25 );
add( txtItemValue ); // add txtActor to JFrame
lblInventoryValue = new JTextField( "Total Inventory Value", 25 );
lblInventoryValue.setEditable( false ); // disable editing
add( lblInventoryValue );
txtInventoryValue = new JTextField(invTotal, 25 );
add( txtInventoryValue ); // 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",iconDelete);
addJButton = new JButton ( "Add",iconAdd);

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



// create new ButtonHandler for button event handling
ButtonHandler handler = new ButtonHandler();
addJButton.addActionListener ( handler );
firstJButton.addActionListener( handler );
prevJButton.addActionListener( handler );
nextJButton.addActionListener( handler );
lastJButton.addActionListener( handler );
deleteJButton.addActionListener( 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.println("In Action Command - Current Event is " + event.getActionCommand());

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


currentArrayCounter++;
}
else if (event.getActionCommand()== "Prev"){
currentArrayCounter--;
}
else if (event.getActionCommand()== "Last"){
currentArrayCounter= arrayCount-1;
}
else if (event.getActionCommand()== "First"){
currentArrayCounter = 0;
}
else if (event.getActionCommand()== "Add"){
currentArrayCounter=arrayCount+1;
}
else if (event.getActionCommand()== "Add"){
arrayDVDs[currentArrayCounter].addOneToQuantity();
System.out.println("Adding");
}
else if (event.getActionCommand()== "Delete"){
arrayDVDs[currentArrayCounter].removeOneFromQuantity();
System.out.println("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 (currentArrayCounter == arrayCount)
{
currentArrayCounter = 0;
}

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

// System.out.println(currentArrayCounter); // Debug statement

NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US); //Provides Locale appropriate currency format

txtActor.setText(arrayDVDs[currentArrayCounter].getactor());
txtItemNum.setText(arrayDVDs[currentArrayCounter].getitemnumber());
txtTitle.setText(arrayDVDs[currentArrayCounter].gettitle());
txtQuantity.setText(Double.toString(arrayDVDs[currentArrayCounter].getquantity()));
txtUnitPrice.setText(Double.toString(arrayDVDs[currentArrayCounter].getunitprice()));
String stringRestockFee = n.format(arrayDVDs[currentArrayCounter].CalculateRestockFee());
txtRestockFee.setText(stringRestockFee);
txtItemValue.setText(n.format(arrayDVDs[currentArrayCounter].calculateDVDValue()));


}


} // end class ButtonFrame
Jun 1 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

109
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
3
MonolithTMA
by: MonolithTMA | last post by:
Greetings all, I am new here, and aside from my introductory post, this will be my first. I am working on an Inventory program for a class I am taking. I've searched the forums here and have...
1
by: mistb2002 | last post by:
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 what am I missing? ...
3
by: cblank | last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory...
5
by: cblank | last post by:
I'm having some trouble with my inventory program. Its due tom and my teacher is not wanting to help. He keeps giving me a soluction that is not related to my code. I have everything working except...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
2
by: blitz1989 | last post by:
Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the...
16
by: lilsugaman | last post by:
I have to assignment which includes the following: Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.