473,287 Members | 1,564 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,287 software developers and data experts.

Java Button Help!

I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone help? my script is below. thank you


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*; //import all java.awt
  2. import java.awt.event.*; //import all java.awt.event
  3. import java.util.*; //import all java.util 
  4. import javax.swing.*; //import all javax.swing
  5.  
  6. class Product //start Product superclass
  7.  
  8.  
  9.  
  10.  
  11.  public String[] ItemName; //item's name
  12.  public int[] ItemNumber; //items's unique product number
  13.  public int[] ItemQuantity; //item's quantity in stock
  14.  public double[] ItemPrice; //item's price per
  15.  
  16.  public Product(String[] name, int[] number, int[] quantity, double[] price) //product constructor
  17.  { 
  18.   ItemName = name; //set ItemName to name
  19.   ItemNumber = number; //set ItemNumber to number
  20.   ItemQuantity = quantity; //set ItemQuantity to quantity
  21.   ItemPrice = price; //set ItemPrice to price  
  22.  } //end Product constructor
  23.  
  24.  public Product SortedArray(Product InvPart2) //start Product method SortedArray
  25.  { 
  26.   String[] name=new String[InvPart2.ItemName.length]; //new name for sorting array
  27.   int [] number = new int[InvPart2.ItemNumber.length]; //new number for sorting array
  28.   int[] quantity = new int[InvPart2.ItemQuantity.length]; //new quantity for sorting array
  29.   double [] price = new double [InvPart2.ItemPrice.length]; //new price for sorting array
  30.   name = (String[])InvPart2.ItemName.clone(); // place name in sorting array 
  31.   Arrays.sort(name); //sort by name
  32.   for (int counter = 0; counter < name.length; counter++) //loop and counter for sorting array
  33.   {
  34.    for(int counter2=0;counter2<name.length;counter2++) 
  35.     //loop and counter to match unsorted array and sorted one
  36.    {
  37.     if(name[counter].equals(InvPart2.ItemName[counter2]))
  38.      //if statement for when a match occurs
  39.     {
  40.      quantity[counter]=InvPart2.ItemQuantity[counter2];
  41.       //set quantity equal to sorted array quantity
  42.      price[counter]=InvPart2.ItemPrice[counter2];
  43.       //set price equal to sorted array price
  44.      number[counter]=InvPart2.ItemNumber[counter2];
  45.       //set number equal to sorted array number
  46.      break; //break for if statement
  47.     } //end if statement  
  48.  
  49.    } //end for loop counter2
  50.  
  51.   } //end for loop counter
  52.   Product SortedProductArray = new Product (name, number, quantity, price);
  53.    //new sorted product array replace old product array
  54.   return SortedProductArray; //return new product array sorted
  55.  } //end Product method SortedArray
  56.  
  57.  public double TotalInvWorth(int[] quantity, double[] price) //start Product method TotalInvWorth
  58.  { 
  59.   double total=0.00F; //set double total = 0
  60.  for (int counter = 0; counter < quantity.length; counter++)
  61.    //loop and counter to multiply each quantity x price in array
  62.   {
  63.   double perprodworth=quantity[counter]*price[counter];
  64.    // multiply quantity x price per counter in array = perprodworth
  65.   total=total+perprodworth; //add perprodworth to total
  66.   }
  67.  return total; //return total in TotalInvWorth
  68.  } //end Product method TotalInvWorth
  69.  
  70. } //end Product superclass
  71.  
  72. class DVD extends Product //start DVD subclass of Product
  73. {
  74.  public int[] NumberOfDisc; //new feature number of disc in movie
  75.  public DVD(String[] name, int[] number, int[] quantity, double[] price, int[] numdisc)
  76.   //dvd constructor
  77.  { 
  78.   super(name, number, quantity, price); //variables from superclass Product
  79.   NumberOfDisc=numdisc; //new variable number of disc per dvd
  80.  } //end dvd constructor
  81.  
  82.  public DVD SortedArray(DVD Inventory5) //start DVD method SortedArray
  83.  { 
  84.   int [] numdisc = new int[Inventory5.NumberOfDisc.length]; //new number for sorting array
  85.   Product DVDProduct=new Product(Inventory5.ItemName,Inventory5.ItemNumber,
  86.     Inventory5.ItemQuantity,Inventory5.ItemPrice); //set DVDProduct equal to superclass array
  87.   Product SortedDVDProduct=super.SortedArray(DVDProduct);    
  88.   for (int counter = 0; counter < SortedDVDProduct.ItemName.length; counter++) //loop and counter for sorting array
  89.   {
  90.    for(int counter2=0;counter2<Inventory5.ItemName.length;counter2++) 
  91.     //loop and counter to match unsorted array and sorted one
  92.    {
  93.     if(SortedDVDProduct.ItemName[counter].equals(Inventory5.ItemName[counter2]))
  94.      //if statement for when a match occurs
  95.     {     
  96.      numdisc[counter]=Inventory5.NumberOfDisc[counter2];
  97.      break; //break for if statement
  98.     } //end if statement
  99.  
  100.    } //end counter2 loop
  101.  
  102.   } //end counter loop
  103.   DVD SortedProductArray = new DVD(SortedDVDProduct.ItemName, SortedDVDProduct.ItemNumber,
  104.     SortedDVDProduct.ItemQuantity, SortedDVDProduct.ItemPrice,numdisc);
  105.    //set SortedProductArray equal to superclass array plus new feature
  106.   return SortedProductArray; //return sortedproductarray
  107.  } //end DVD method SortedArray
  108.  
  109.  public double DVDRestock () //start DVD method DVDRestock
  110.  {
  111.  double totalInvworthbeforerestockingfee=super.TotalInvWorth(ItemQuantity, ItemPrice);
  112.   //set totalInvWorthBeforeRestockingFee to TotalInvWorth in superclass
  113.  double restockfee=0.00F; //set restock fee to 0
  114.  double totalinvworthwithrestockfee=0.00F; //set toatal worth after fee to 0
  115.  restockfee = 0.05F*totalInvworthbeforerestockingfee; //restock fee = 5% to invworth before fee
  116.  totalinvworthwithrestockfee=restockfee+totalInvworthbeforerestockingfee; //add 5% to original inv worth
  117.  return totalinvworthwithrestockfee; //return inv total with fee
  118.  } //end DVD method DVDRestock
  119.  
  120. } //end DVD subclass
  121.  
  122. public class Inventory5 extends JFrame implements ActionListener 
  123. { // start class Inventory5
  124.  
  125.  public Inventory5()
  126.  { //start Inventory5 constructor
  127.   this.initialize(); //set initialize
  128.  } //end Inventory5 constructor
  129.  
  130.  private JTextArea text = new JTextArea(); //initializing jtextarea
  131.  private JButton firstBtn; //initializing first Jbutton
  132.  private JButton prevBtn; //initializing previous Jbutton
  133.  private JButton nextBtn; //initializing next Jbutton
  134.  private JButton lastBtn; //initializing last Jbutton
  135.  private JButton logoBtn; //initializing logo Jbutton
  136.  private ImageIcon logo = new ImageIcon("logo.gif"); //initializing picture for logo Jbutton
  137.  private int buttonCounter; //initializing buttonCounter for place in array
  138.  
  139.  public void initialize() //start initialize method
  140.  {
  141.   firstBtn=new JButton("First"); //set firstBtn to JButton First
  142.   prevBtn=new JButton("Previous"); //set prevBtn to JButton Previous
  143.   nextBtn=new JButton("Next"); //set nextBtn to JButton Next
  144.   lastBtn=new JButton("Last"); //set lastBtn to JButton Last
  145.   logoBtn = new JButton(logo); //set logoBtn to JButton logo
  146.  
  147.   this.getContentPane().add(this.logoBtn); //add logoBtn to content pane
  148.   this.logoBtn.setBounds(0, 0, 75, 75); //set logoBtn's size
  149.   this.logoBtn.setBorderPainted(false); //turn border off for logoBtn
  150.  
  151.   this.getContentPane().add(this.firstBtn); //add firstBtn to content pane
  152.   this.firstBtn.setBounds(40, 300, 100, 30); //set firstBtn's size
  153.   this.firstBtn.setActionCommand("FIRST"); //set action command for firstBtn to FIRST
  154.   this.firstBtn.addActionListener(this); //set action lisnter for firstBtn
  155.  
  156.   this.getContentPane().add(this.prevBtn); //add prevBtn to content pane
  157.   this.prevBtn.setBounds(150, 300, 100, 30); //set prevBtn's size
  158.   this.prevBtn.setActionCommand("PREV"); //set action command for prevBtn to PREV
  159.   this.prevBtn.addActionListener(this); //set action lisnter for prevBtn
  160.  
  161.   this.getContentPane().add(this.nextBtn); //add nextBtn to content pane
  162.   this.nextBtn.setBounds(260, 300, 100, 30); //set nextBtn's size
  163.   this.nextBtn.setActionCommand("NEXT");  //set action command for nextBtn to NEXT
  164.   this.nextBtn.addActionListener(this); //set action lisnter for nextBtn
  165.  
  166.   this.getContentPane().add(this.lastBtn); //add lastBtn to content pane
  167.   this.lastBtn.setBounds(370, 300, 100, 30); //set lastBtn's size
  168.   this.lastBtn.setActionCommand("LAST"); //set action command for lastBtn to LAST
  169.   this.lastBtn.addActionListener(this); //set action lisnter for lastBtn
  170.  
  171.   this.getContentPane().add(this.text,BorderLayout.CENTER); //add text to window
  172.   this.setSize(520, 400); //set frame size
  173.   this.setResizable(false); //set frame resizable
  174.   this.setVisible(true); //set frame visiable
  175.   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //add to properly close app
  176.  } //end initialize method
  177.  
  178.  
  179.  public static void main(String[] args) //start main method
  180.  {
  181.  
  182.   Inventory5 part4=new Inventory5();   
  183.   part4.processing(part4.buttonCounter);
  184.   //needed to call processing method
  185.  
  186.  } //end main method
  187.  
  188.  private void processing(int counter) //start processing method
  189.  {
  190.   //setting static data for variables in each array
  191.   String[] name = {"Star Trek", "Star Gate", "Fifth Element", "Armageddon", "Star Wars  "};
  192.   int[] number = {1, 2, 4, 5, 7};
  193.   int[] quantity = {2, 5, 6, 3, 9};
  194.   double[] price = {(double) 15.99, (double) 16.99, (double) 11.99,
  195.     (double) 13.95, (double) 14.95};
  196.   int[] numDisks= {1,2,1,2,1};
  197.   StringBuffer output=new StringBuffer(""); //new stringbuffer for output
  198.  
  199.   Product Inventory5 = new Product (name, number, quantity, price);
  200.    //needed to reslove Product constructor  
  201.  
  202.   output.append(String.format("\n\n\n\n\n\nBefore Restocking Fee, Inventory Is Worth A Total Of: $%.2f\n",
  203.     Inventory5.TotalInvWorth(Inventory5.ItemQuantity,Inventory5.ItemPrice)));
  204.   //output to string total worth of inventory before fee
  205.  
  206.   DVD DVDSub  = new DVD (name, number, quantity, price, numDisks);
  207.    //needed to reslove DVD constructor
  208.  
  209.   DVD SortedDVD = DVDSub.SortedArray(DVDSub);
  210.   //needed to replace original arrays with sorted one with new feature 
  211.  
  212.   output.append(String.format("After Restocking Fee of 5 Percent," +
  213.     " Inventory Is Worth A Total Of: $%.2f\n\n",DVDSub.DVDRestock()));
  214.    //output to string total worth of inventory after fee
  215.  
  216.   output.append(String.format("Inventory\n")); //output to string inventory list
  217.   output.append(String.format("DVD Name:\tProdID:\tStock:\tPrice:\tDVDDisc:\n")); //output to string headers
  218.  
  219.  
  220.  
  221.   output.append(String.format("%s\t%d\t%d\t%.2f\t%d\t\n",SortedDVD.ItemName[counter], SortedDVD.ItemNumber[counter], 
  222.      SortedDVD.ItemQuantity[counter],SortedDVD.ItemPrice[counter],SortedDVD.NumberOfDisc[counter]));
  223.    //out for array buttonCounter determines where in which line of array is outputed
  224.  
  225.  
  226.   this.text.setText(output.toString()); //output all text to String to place in GUI
  227.  
  228.  } //end processing method
  229.  
  230.  
  231.  public void actionPerformed (ActionEvent event) //started actionperformed method
  232.  {
  233.  
  234.   this.initialize(); //initialize window
  235.  
  236.   if(((JButton)event.getSource()).getActionCommand().equals("FIRST")) //if statement for first button
  237.   {
  238.    this.buttonCounter=0; //set buttonCounter to 0
  239.   }
  240.  
  241.   else if(((JButton)event.getSource()).getActionCommand().equals("PREV")) //if statement for prev button
  242.   {
  243.    if (this.buttonCounter > 0) //if statement for only if buttonCounter is greater than 0
  244.     this.buttonCounter=--this.buttonCounter; //-1 from buttonCounter
  245.   }
  246.  
  247.   else if(((JButton)event.getSource()).getActionCommand().equals("NEXT")) //if statement for next button
  248.   {
  249.    if (this.buttonCounter < 4) //if statement for only if buttonCounter is less than 4
  250.     this.buttonCounter=++this.buttonCounter; //+1 to buttonCounter
  251.   }
  252.  
  253.   else if(((JButton)event.getSource()).getActionCommand().equals("LAST"))
  254.   {
  255.    this.buttonCounter=4; //set buttonCounter to 4
  256.   }
  257.  
  258.   this.processing(this.buttonCounter); //return buttonCounter to processing method
  259.  
  260.  } //end actionperformed method
  261.  
  262. } // end class Inventory5
May 17 '07 #1
2 2855
JosAH
11,448 Expert 8TB
Greetings,

I changed your topic title to avoid confusion: Java is not Javascript and Java
programs aren't scripts. I also added code tags for readability reasons.

I'm afraid that not many people are going to read that much code in order to
figure out where it would be possible to add code for some buttons for you.
Better show a small piece of code that's giving your some trouble and ask
a coherent question about it. Thanks.

kind regards,

Jos
May 17 '07 #2
r035198x
13,262 8TB
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone help? my script is below. thank you


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*; //import all java.awt
  2. import java.awt.event.*; //import all java.awt.event
  3. import java.util.*; //import all java.util 
  4. import javax.swing.*; //import all javax.swing
  5.  
  6. class Product //start Product superclass
  7.  
  8.  
  9.  
  10.  
  11. public String[] ItemName; //item's name
  12. public int[] ItemNumber; //items's unique product number
  13. public int[] ItemQuantity; //item's quantity in stock
  14. public double[] ItemPrice; //item's price per
  15.  
  16. public Product(String[] name, int[] number, int[] quantity, double[] price) //product constructor
  17. ItemName = name; //set ItemName to name
  18. ItemNumber = number; //set ItemNumber to number
  19. ItemQuantity = quantity; //set ItemQuantity to quantity
  20. ItemPrice = price; //set ItemPrice to price 
  21. } //end Product constructor
  22.  
  23. public Product SortedArray(Product InvPart2) //start Product method SortedArray
  24. String[] name=new String[InvPart2.ItemName.length]; //new name for sorting array
  25. int [] number = new int[InvPart2.ItemNumber.length]; //new number for sorting array
  26. int[] quantity = new int[InvPart2.ItemQuantity.length]; //new quantity for sorting array
  27. double [] price = new double [InvPart2.ItemPrice.length]; //new price for sorting array
  28. name = (String[])InvPart2.ItemName.clone(); // place name in sorting array 
  29. Arrays.sort(name); //sort by name
  30. for (int counter = 0; counter < name.length; counter++) //loop and counter for sorting array
  31. {
  32. for(int counter2=0;counter2<name.length;counter2++) 
  33. //loop and counter to match unsorted array and sorted one
  34. {
  35. if(name[counter].equals(InvPart2.ItemName[counter2]))
  36. //if statement for when a match occurs
  37. {
  38. quantity[counter]=InvPart2.ItemQuantity[counter2];
  39. //set quantity equal to sorted array quantity
  40. price[counter]=InvPart2.ItemPrice[counter2];
  41. //set price equal to sorted array price
  42. number[counter]=InvPart2.ItemNumber[counter2];
  43. //set number equal to sorted array number
  44. break; //break for if statement
  45. } //end if statement 
  46.  
  47. } //end for loop counter2
  48.  
  49. } //end for loop counter
  50. Product SortedProductArray = new Product (name, number, quantity, price);
  51. //new sorted product array replace old product array
  52. return SortedProductArray; //return new product array sorted
  53. } //end Product method SortedArray
  54.  
  55. public double TotalInvWorth(int[] quantity, double[] price) //start Product method TotalInvWorth
  56. double total=0.00F; //set double total = 0
  57. for (int counter = 0; counter < quantity.length; counter++)
  58. //loop and counter to multiply each quantity x price in array
  59. {
  60. double perprodworth=quantity[counter]*price[counter];
  61. // multiply quantity x price per counter in array = perprodworth
  62. total=total+perprodworth; //add perprodworth to total
  63. }
  64. return total; //return total in TotalInvWorth
  65. } //end Product method TotalInvWorth
  66.  
  67. } //end Product superclass
  68.  
  69. class DVD extends Product //start DVD subclass of Product
  70. {
  71. public int[] NumberOfDisc; //new feature number of disc in movie
  72. public DVD(String[] name, int[] number, int[] quantity, double[] price, int[] numdisc)
  73. //dvd constructor
  74. super(name, number, quantity, price); //variables from superclass Product
  75. NumberOfDisc=numdisc; //new variable number of disc per dvd
  76. } //end dvd constructor
  77.  
  78. public DVD SortedArray(DVD Inventory5) //start DVD method SortedArray
  79. int [] numdisc = new int[Inventory5.NumberOfDisc.length]; //new number for sorting array
  80. Product DVDProduct=new Product(Inventory5.ItemName,Inventory5.ItemNumber,
  81. Inventory5.ItemQuantity,Inventory5.ItemPrice); //set DVDProduct equal to superclass array
  82. Product SortedDVDProduct=super.SortedArray(DVDProduct); 
  83. for (int counter = 0; counter < SortedDVDProduct.ItemName.length; counter++) //loop and counter for sorting array
  84. {
  85. for(int counter2=0;counter2<Inventory5.ItemName.length;counter2++) 
  86. //loop and counter to match unsorted array and sorted one
  87. {
  88. if(SortedDVDProduct.ItemName[counter].equals(Inventory5.ItemName[counter2]))
  89. //if statement for when a match occurs
  90. numdisc[counter]=Inventory5.NumberOfDisc[counter2];
  91. break; //break for if statement
  92. } //end if statement
  93.  
  94. } //end counter2 loop
  95.  
  96. } //end counter loop
  97. DVD SortedProductArray = new DVD(SortedDVDProduct.ItemName, SortedDVDProduct.ItemNumber,
  98. SortedDVDProduct.ItemQuantity, SortedDVDProduct.ItemPrice,numdisc);
  99. //set SortedProductArray equal to superclass array plus new feature
  100. return SortedProductArray; //return sortedproductarray
  101. } //end DVD method SortedArray
  102.  
  103. public double DVDRestock () //start DVD method DVDRestock
  104. {
  105. double totalInvworthbeforerestockingfee=super.TotalInvWorth(ItemQuantity, ItemPrice);
  106. //set totalInvWorthBeforeRestockingFee to TotalInvWorth in superclass
  107. double restockfee=0.00F; //set restock fee to 0
  108. double totalinvworthwithrestockfee=0.00F; //set toatal worth after fee to 0
  109. restockfee = 0.05F*totalInvworthbeforerestockingfee; //restock fee = 5% to invworth before fee
  110. totalinvworthwithrestockfee=restockfee+totalInvworthbeforerestockingfee; //add 5% to original inv worth
  111. return totalinvworthwithrestockfee; //return inv total with fee
  112. } //end DVD method DVDRestock
  113.  
  114. } //end DVD subclass
  115.  
  116. public class Inventory5 extends JFrame implements ActionListener 
  117. { // start class Inventory5
  118.  
  119. public Inventory5()
  120. { //start Inventory5 constructor
  121. this.initialize(); //set initialize
  122. } //end Inventory5 constructor
  123.  
  124. private JTextArea text = new JTextArea(); //initializing jtextarea
  125. private JButton firstBtn; //initializing first Jbutton
  126. private JButton prevBtn; //initializing previous Jbutton
  127. private JButton nextBtn; //initializing next Jbutton
  128. private JButton lastBtn; //initializing last Jbutton
  129. private JButton logoBtn; //initializing logo Jbutton
  130. private ImageIcon logo = new ImageIcon("logo.gif"); //initializing picture for logo Jbutton
  131. private int buttonCounter; //initializing buttonCounter for place in array
  132.  
  133. public void initialize() //start initialize method
  134. {
  135. firstBtn=new JButton("First"); //set firstBtn to JButton First
  136. prevBtn=new JButton("Previous"); //set prevBtn to JButton Previous
  137. nextBtn=new JButton("Next"); //set nextBtn to JButton Next
  138. lastBtn=new JButton("Last"); //set lastBtn to JButton Last
  139. logoBtn = new JButton(logo); //set logoBtn to JButton logo
  140.  
  141. this.getContentPane().add(this.logoBtn); //add logoBtn to content pane
  142. this.logoBtn.setBounds(0, 0, 75, 75); //set logoBtn's size
  143. this.logoBtn.setBorderPainted(false); //turn border off for logoBtn
  144.  
  145. this.getContentPane().add(this.firstBtn); //add firstBtn to content pane
  146. this.firstBtn.setBounds(40, 300, 100, 30); //set firstBtn's size
  147. this.firstBtn.setActionCommand("FIRST"); //set action command for firstBtn to FIRST
  148. this.firstBtn.addActionListener(this); //set action lisnter for firstBtn
  149.  
  150. this.getContentPane().add(this.prevBtn); //add prevBtn to content pane
  151. this.prevBtn.setBounds(150, 300, 100, 30); //set prevBtn's size
  152. this.prevBtn.setActionCommand("PREV"); //set action command for prevBtn to PREV
  153. this.prevBtn.addActionListener(this); //set action lisnter for prevBtn
  154.  
  155. this.getContentPane().add(this.nextBtn); //add nextBtn to content pane
  156. this.nextBtn.setBounds(260, 300, 100, 30); //set nextBtn's size
  157. this.nextBtn.setActionCommand("NEXT"); //set action command for nextBtn to NEXT
  158. this.nextBtn.addActionListener(this); //set action lisnter for nextBtn
  159.  
  160. this.getContentPane().add(this.lastBtn); //add lastBtn to content pane
  161. this.lastBtn.setBounds(370, 300, 100, 30); //set lastBtn's size
  162. this.lastBtn.setActionCommand("LAST"); //set action command for lastBtn to LAST
  163. this.lastBtn.addActionListener(this); //set action lisnter for lastBtn
  164.  
  165. this.getContentPane().add(this.text,BorderLayout.CENTER); //add text to window
  166. this.setSize(520, 400); //set frame size
  167. this.setResizable(false); //set frame resizable
  168. this.setVisible(true); //set frame visiable
  169. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //add to properly close app
  170. } //end initialize method
  171.  
  172.  
  173. public static void main(String[] args) //start main method
  174. {
  175.  
  176. Inventory5 part4=new Inventory5(); 
  177. part4.processing(part4.buttonCounter);
  178. //needed to call processing method
  179.  
  180. } //end main method
  181.  
  182. private void processing(int counter) //start processing method
  183. {
  184. //setting static data for variables in each array
  185. String[] name = {"Star Trek", "Star Gate", "Fifth Element", "Armageddon", "Star Wars "};
  186. int[] number = {1, 2, 4, 5, 7};
  187. int[] quantity = {2, 5, 6, 3, 9};
  188. double[] price = {(double) 15.99, (double) 16.99, (double) 11.99,
  189. (double) 13.95, (double) 14.95};
  190. int[] numDisks= {1,2,1,2,1};
  191. StringBuffer output=new StringBuffer(""); //new stringbuffer for output
  192.  
  193. Product Inventory5 = new Product (name, number, quantity, price);
  194. //needed to reslove Product constructor 
  195.  
  196. output.append(String.format("\n\n\n\n\n\nBefore Restocking Fee, Inventory Is Worth A Total Of: $%.2f\n",
  197. Inventory5.TotalInvWorth(Inventory5.ItemQuantity,Inventory5.ItemPrice)));
  198. //output to string total worth of inventory before fee
  199.  
  200. DVD DVDSub = new DVD (name, number, quantity, price, numDisks);
  201. //needed to reslove DVD constructor
  202.  
  203. DVD SortedDVD = DVDSub.SortedArray(DVDSub);
  204. //needed to replace original arrays with sorted one with new feature 
  205.  
  206. output.append(String.format("After Restocking Fee of 5 Percent," +
  207. " Inventory Is Worth A Total Of: $%.2f\n\n",DVDSub.DVDRestock()));
  208. //output to string total worth of inventory after fee
  209.  
  210. output.append(String.format("Inventory\n")); //output to string inventory list
  211. output.append(String.format("DVD Name:\tProdID:\tStock:\tPrice:\tDVDDisc:\n")); //output to string headers
  212.  
  213.  
  214.  
  215. output.append(String.format("%s\t%d\t%d\t%.2f\t%d\t\n",SortedDVD.ItemName[counter], SortedDVD.ItemNumber[counter], 
  216. SortedDVD.ItemQuantity[counter],SortedDVD.ItemPrice[counter],SortedDVD.NumberOfDisc[counter]));
  217. //out for array buttonCounter determines where in which line of array is outputed
  218.  
  219.  
  220. this.text.setText(output.toString()); //output all text to String to place in GUI
  221.  
  222. } //end processing method
  223.  
  224.  
  225. public void actionPerformed (ActionEvent event) //started actionperformed method
  226. {
  227.  
  228. this.initialize(); //initialize window
  229.  
  230. if(((JButton)event.getSource()).getActionCommand().equals("FIRST")) //if statement for first button
  231. {
  232. this.buttonCounter=0; //set buttonCounter to 0
  233. }
  234.  
  235. else if(((JButton)event.getSource()).getActionCommand().equals("PREV")) //if statement for prev button
  236. {
  237. if (this.buttonCounter > 0) //if statement for only if buttonCounter is greater than 0
  238. this.buttonCounter=--this.buttonCounter; //-1 from buttonCounter
  239. }
  240.  
  241. else if(((JButton)event.getSource()).getActionCommand().equals("NEXT")) //if statement for next button
  242. {
  243. if (this.buttonCounter < 4) //if statement for only if buttonCounter is less than 4
  244. this.buttonCounter=++this.buttonCounter; //+1 to buttonCounter
  245. }
  246.  
  247. else if(((JButton)event.getSource()).getActionCommand().equals("LAST"))
  248. {
  249. this.buttonCounter=4; //set buttonCounter to 4
  250. }
  251.  
  252. this.processing(this.buttonCounter); //return buttonCounter to processing method
  253.  
  254. } //end actionperformed method
  255.  
  256. } // end class Inventory5
Did you write this code?
May 17 '07 #3

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

Similar topics

0
by: Martin | last post by:
Hi All, I am a relative newbie to Java / Applets, but am despirately after some help ! I have got the following code, which is basically a listing with button items along the sides, allowing...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
4
by: Khan | last post by:
hi, i'm writing java code inside <body> tag of java script file. all the java code is executing at frame startup. how can i call that java code only when i click on a button. I can call jscript...
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...
7
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to...
1
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next...
2
by: pinkf24 | last post by:
I cannot figure out how to add the following: Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform...
5
by: xirowei | last post by:
public class Result { private int countA = 0; private int countB = 0; private int statement; private boolean statusA = false; private boolean statusB = false; private int arrayA = new...
10
by: yeshello54 | last post by:
Hey guys i am pretty new to java swing and need some help. I am developing a simple color chooser program in swing. I have a color panel that is connected to three sliders. red green and blue. but...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.