Inventory Application for DVDs

Reply

Join Date: Sep 2006
Posts: 1
Reputation: Comtek1980 is an unknown quantity at this point 
Solved Threads: 0
Comtek1980 Comtek1980 is offline Offline
Newbie Poster

Inventory Application for DVDs

 
0
  #1
Sep 8th, 2006
I am having trouble correcting the errors in my application to get it to compile. My deadline for this app is Oct. 1. I would appreciate if a fresh set of eyes could look at my code and see where I'm going wrong. Thanks

  1. import java.util.Arrays;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6.  
  7.  
  8. public class Inventory {
  9.  
  10. {
  11.  
  12. final int arrayLength = 4;
  13. int productNum[] = new int[ arrayLength];
  14. String productName[] = new String[] { "X-Men" , "LOST", "Fragile Rock", "KiKi's Delivery Service" };
  15. int productUnits[] = { 25, 20, 40, 50 };
  16. double productPrice[] = { 10.00, 25.00, 4.00, 9.99 };
  17. double productValue[] = new double[ arrayLength ];
  18.  
  19.  
  20. sortProductName( productName );
  21.  
  22. for ( int counter = 0 ; counter < productNum.length; counter++ );
  23. }
  24.  
  25.  
  26. public static void outputTotalValue( double productValue[] )
  27.  
  28. {
  29. double totalProductValue = 0;
  30.  
  31. for ( int counter = 0; counter < productValue.length; counter++ )
  32.  
  33. totalProductValue += productValue[ counter ];
  34. }
  35.  
  36. public static void sortProductName( String productName[] )
  37. {
  38. Arrays.sort( productName );
  39. }
  40.  
  41.  
  42. public class Rating extends Inventory
  43. {
  44. private boolean ratingG, ratingPg, ratingR;
  45.  
  46. public Rating(String color) {
  47. ratingG = false;
  48. ratingPg = true;
  49. ratingR = false;
  50. }
  51. //already has method to calculate the value of the inventory of a product
  52.  
  53.  
  54. }
  55. public int numClicks = 0;
  56. JLabel label = new JLabel("Item number");
  57. JLabel label1 = new JLabel("Name of product");
  58. JLabel label2 = new JLabel("Number of units in stock");
  59. JLabel label3 = new JLabel("Price of unit");
  60. JLabel label4 = new JLabel("Value of product inventory");
  61. JLabel label5 = new JLabel("Product rating");
  62. JLabel label6 = new JLabel("Restocking fee");
  63. JLabel label7 = new JLabel("Entire inventory value");
  64.  
  65. final static String LOOKANDFEEL = null;
  66.  
  67. public Component createComponents() {
  68. JButton button = new JButton("Click me to see products");
  69. button.setMnemonic(KeyEvent.VK_I);
  70. button.addActionListener(this);
  71. label.setLabelFor(button);
  72.  
  73. JButton button = new JButton1("First");
  74. button.setMnemonic(KeyEvent.VK_I);
  75. button.addActionListener(this);
  76. label.setLabelFor(button1);
  77.  
  78. JButton button = new JButton2("Next");
  79. button.setMnemonic(KeyEvent.VK_I);
  80. button.addActionListener(this);
  81. label.setLabelFor(button2);
  82.  
  83. JButton button = new JButton3("Previous");
  84. button.setMnemonic(KeyEvent.VK_I);
  85. button.addActionListener(this);
  86. label.setLabelFor(button3);
  87.  
  88. JButton button = new JButton4("Last");
  89. button.setMnemonic(KeyEvent.VK_I);
  90. button.addActionListener(this);
  91. label.setLabelFor(button4);
  92.  
  93. JPanel pane = new JPanel(new GridLayout(0, 1));
  94. pane.add(button);
  95. pane.add(button1);
  96. pane.add(button2);
  97. pane.add(button3);
  98. pane.add(button4);
  99. pane.add(label);
  100. pane.add(label1);
  101. pane.add(label2);
  102. pane.add(label3);
  103. pane.add(label4);
  104. pane.add(label5);
  105. pane.add(label6);
  106. pane.add(label7);
  107. pane.setBorder(BorderFactory.createEmptyBorder(
  108. 30, //top
  109. 30, //left
  110. 20, //bottom
  111. 30) //right
  112. );
  113.  
  114. return pane;
  115. }
  116.  
  117. public void actionPerformed(ActionEvent e){
  118.  
  119. label.setText(productName[0]);
  120. label1.setText(productName[1]);
  121. label2.setText(productName[2]);
  122. }
  123.  
  124.  
  125.  
  126. {
  127. final int arrayLength = 4;
  128. int productNum[] = new int[ arrayLength];
  129. String productName[] = new String[] { "X-Men" , "LOST", "Fragile Rock", "KiKi's Delivery Service" };
  130. int productUnits[] = { 25, 20, 40, 50 };
  131. double productPrice[] = { 10.00, 25.00, 4.00, 9.99 };
  132. double productValue[] = new double[ arrayLength ];
  133.  
  134.  
  135.  
  136. }
  137. }
  138.  
  139. public static void initLookAndFeel() {
  140.  
  141. String lookAndFeel = null;
  142.  
  143. if (LOOKANDFEEL != null) {
  144. if (LOOKANDFEEL.equals("Metal")) {
  145. lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
  146. } else if (LOOKANDFEEL.equals("System")) {
  147. lookAndFeel = UIManager.getSystemLookAndFeelClassName();
  148. } else if (LOOKANDFEEL.equals("Motif")) {
  149. lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
  150. } else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
  151. lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
  152. } else {
  153. System.err.println("Unexpected value of LOOKANDFEEL specified: "
  154. + LOOKANDFEEL);
  155. lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
  156. }
  157.  
  158. try {
  159. UIManager.setLookAndFeel(lookAndFeel);
  160. } catch (ClassNotFoundException e) {
  161. System.err.println("Couldn't find class for specified look and feel:"
  162. + lookAndFeel);
  163. System.err.println("Did you include the L&F library in the class path?");
  164. System.err.println("Using the default look and feel.");
  165. } catch (UnsupportedLookAndFeelException e) {
  166. System.err.println("Can't use the specified look and feel ("
  167. + lookAndFeel
  168. + ") on this platform.");
  169. System.err.println("Using the default look and feel.");
  170. } catch (Exception e) {
  171. System.err.println("Couldn't get specified look and feel ("
  172. + lookAndFeel
  173. + "), for some reason.");
  174. System.err.println("Using the default look and feel.");
  175. e.printStackTrace();
  176. }
  177. }
  178.  
  179.  
  180. private static void createAndShowGUI() {
  181.  
  182. initLookAndFeel();
  183.  
  184. JFrame.setDefaultLookAndFeelDecorated(true);
  185.  
  186. JFrame frame = new JFrame("DVD Inventory");
  187. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  188.  
  189. Inventory app = new Inventory();
  190. Component contents = app.createComponents();
  191. frame.getContentPane().add(contents, BorderLayout.CENTER);
  192.  
  193. frame.pack();
  194. frame.setVisible(true);
  195.  
  196. }
  197.  
  198. public static void main(String[] args) {
  199. javax.swing.SwingUtilities.invokeLater(new Runnable() {
  200. public void run() {
  201. createAndShowGUI();
  202. }
  203. });
  204.  
  205. public class ImageTest extends GUIFrame {
  206. public ImageTest() {
  207. super("Image Test");
  208. setSize(65,88);
  209. setBackground(Color.red);
  210. }
  211.  
  212. public static void main(String args[]) {
  213. new ImageTest().setVisible(true);
  214. }
  215.  
  216. public void paint(Graphics g) {
  217. Imageimg = Toolkit.getDefaultToolkit().getImage("dvd.jpg");
  218. g.drawImage(img, 0, 0, 64, 88, this);
  219. }
  220. }
  221. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 762
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: Inventory Application for DVDs

 
0
  #2
Sep 9th, 2006
Care to tell us the errors you're receiving?


Took a glance at it, oh where do I even begin.

What's this?
sortProductName( productName );

Unless its returning a value and assigning it to something, you have to put it inside a method or constructor.

This, too, can not be outside a method. It also never performs any action because of the semicolon after the declaration.

for ( int counter = 0 ; counter < productNum.length; counter++ );

And just after that line, you put the closing bracket for hte class, making the following methods belong to nothing.

Actually, you have a ton of problems with your curly brackets. Many are out of place, some appear just to be the wrong direction of bracket, and some are just plain missing. Go through your whole program, indent everything evenly, and look at those brackets carefully.


Also, before you can add "this" as an ActionListener for the buttons, the class must implement the ActionListener interface.

You're also trying to declare "button" multiple times. Plus you're calling classes that do not exist.

JButton1, JButton2, JButton3

It should be:
JButton button1 = new JButton("First");
JButton button2 = new JButton("Next");
JButton button3 = new JButton("Previous");


By the way, why are you making all your methods static anyway?

Also, put the ImageTest class in a separate file.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC