Inventory graphics prob

Reply

Join Date: May 2008
Posts: 2
Reputation: bjeff71 is an unknown quantity at this point 
Solved Threads: 0
bjeff71 bjeff71 is offline Offline
Newbie Poster

Inventory graphics prob

 
0
  #1
May 30th, 2008
I am having problems with my program. I am altering it to show the GUI which 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 of each unit, the value of the inventory of that product, the entire inventory, the additional attribute, and the restocking fee. Here is what I've got so far:

  1. package inventory4;
  2.  
  3. import java.util.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6. import java.awt.*;
  7.  
  8. public class Inventory4 extends JFrame implements ActionListener {
  9.  
  10. private class MyPanel extends JPanel {
  11.  
  12. ImageIcon image = new ImageIcon("Sample.jpg");
  13. int width = image.getIconWidth();
  14. int height = image.getIconHeight();
  15. long angle = 30;
  16.  
  17. public MyPanel() {
  18. super();
  19. }
  20.  
  21. public void paintComponent(Graphics g) {
  22. super.paintComponent(g);
  23. Graphics2D g2d = (Graphics2D) g;
  24. g2d.rotate(Math.toRadians(angle), 60 + width / 2, 60 + height / 2);
  25. g2d.drawImage(image.getImage(), 60, 60, this);
  26. g2d.dispose();
  27. }
  28. }//end class MyPanel
  29. int currentIndex; //Currently displayed Item
  30. Product[] supplies = new Product[4];
  31. JLabel name;
  32. JLabel number;
  33. JLabel title;
  34. JLabel quantity;
  35. JLabel price;
  36. JLabel fee;
  37. JLabel totalValue;
  38. JTextField nameField = new JTextField(20);
  39. JTextField numberField = new JTextField(20);
  40. JTextField titleField = new JTextField(20);
  41. JTextField quantityField = new JTextField(20);
  42. JTextField priceField = new JTextField(20);
  43. JPanel display;
  44. JPanel displayHolder;
  45. JPanel panel;
  46.  
  47. public Inventory4() {
  48.  
  49.  
  50. setSize(500, 500);
  51. setTitle("Bob's CD Inventory Program");
  52. //make the panels
  53. display = new JPanel();
  54. JPanel other = new JPanel();
  55. JPanel picture = new MyPanel();
  56. JPanel centerPanel = new JPanel();
  57. displayHolder = new JPanel();
  58. display.setLayout(new GridLayout(7, 1));
  59. //other.setLayout(new GridLayout(1, 1));
  60.  
  61. //make the labels
  62. name = new JLabel("Name :");
  63. number = new JLabel("Number :");
  64. title = new JLabel("Title :");
  65. quantity = new JLabel("Quantity :");
  66. price = new JLabel("Price :");
  67. fee = new JLabel("Restocking Fee :");
  68. totalValue = new JLabel("Total Value :");
  69.  
  70.  
  71. //Add the labels to the display panel
  72. display.add(name);
  73. display.add(number);
  74. display.add(title);
  75. display.add(quantity);
  76. display.add(price);
  77. display.add(fee);
  78.  
  79.  
  80. //Add the panels to the frame
  81.  
  82. getContentPane().add(centerPanel, "Center");
  83. getContentPane().add(other, "South");
  84. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  85. setVisible(true);
  86. }
  87. }
  88.  
  89. class CD extends Product {
  90.  
  91. String genre;
  92. double restockingFee;
  93.  
  94. public CD(String genre, double restockingFee, int item, String title, double stockQuantity,
  95. double price) {
  96. //super(title,item, stockQuantity, price);
  97. this.genre = genre;
  98. this.restockingFee = restockingFee;
  99.  
  100. // TODO Auto-generated constructor stub
  101. }
  102.  
  103. //returns the value of the inventory, plus the restocking fee
  104. public double getInventoryValue() {
  105. // TODO Auto-generated method stub
  106. return super.getItemPrice() + restockingFee;
  107. }
  108.  
  109. public String toString() {
  110. StringBuffer sb = new StringBuffer("Genre \t").append(genre).append("\n");
  111. sb.append(super.toString());
  112.  
  113. return sb.toString();
  114. }
  115. }
  116.  
  117. //Inventory4.java
  118. class Product implements Comparable {
  119.  
  120. private String title; // class variable that stores the item name
  121. private int item; // class variable that stores the item number
  122. private double stockQuantity; // class variable that stores the quantity in stock
  123. private double price; // class variable that stores the item price
  124. private String genre;
  125.  
  126. public Product() {
  127. title = "";
  128. item = 0;
  129. stockQuantity = 0;
  130. price = 0.0;
  131. genre = "";
  132. }
  133.  
  134. public Product(String title, String genre, int item, double stockQuantity, double price) {
  135. this.title = title;
  136. this.item = item;
  137. this.stockQuantity = stockQuantity;
  138. this.price = price;
  139. this.genre = genre;
  140. }
  141.  
  142. public void setTitle(String title) {
  143. this.title = title;
  144. }
  145.  
  146. public String getTitle() {
  147. return title;
  148. }
  149.  
  150. public void setItem(int item) {
  151. this.item = item;
  152. }
  153.  
  154. public int getItem() {
  155. return item;
  156. }
  157.  
  158. public void setStockQuantity(double quantity) {
  159. stockQuantity = quantity;
  160. }
  161.  
  162. public double getStockQuantity() {
  163. return stockQuantity;
  164. }
  165.  
  166. public void setItemPrice(double price) {
  167. this.price = price;
  168. }
  169.  
  170. public double getItemPrice() {
  171. return price;
  172. }
  173.  
  174. public void setGenre(String genre) {
  175. this.genre = genre;
  176. }
  177.  
  178. public String getGenre() {
  179. return genre;
  180. }
  181.  
  182. public double calculateInventoryValue() {
  183. return price * stockQuantity;
  184. }
  185.  
  186. public int compareTo(Object o) {
  187. Product p = null;
  188. try {
  189. p = (Product) o;
  190. } catch (ClassCastException cE) {
  191. cE.printStackTrace();
  192. }
  193. return title.compareTo(p.getTitle());
  194. }
  195.  
  196. public String toString() {
  197. return "CD Title: " + title + "\nGenre: " + genre + "\nItem #: " + item + "\nPrice: $" + price + "\nQuantity: " + stockQuantity + "\nValue with restocking fee: $" + (calculateInventoryValue() + (calculateInventoryValue() * .05));
  198. }
  199. }
  200.  
  201. public class Inventory4 {
  202.  
  203. Product[] supplies;
  204.  
  205. public static void main(String[] args) {
  206. Inventory4 inventory = new Inventory4();
  207. inventory.addProduct(new Product("Mozart", "Classical", 1, 54, 11.50));
  208. inventory.addProduct(new Product("Beethoven", "Classical", 2, 65, 12.00));
  209. inventory.addProduct(new Product("Tiny Tim", "Classical", 3, 10, 1.00));
  210.  
  211. System.out.println("Inventory of CD's:\n\n");
  212.  
  213.  
  214. System.out.println();
  215. inventory.showInventory();
  216. System.out.println();
  217.  
  218. double total = inventory.calculateTotalInventory();
  219. System.out.println("Total Value is: $" + (total + (total * .05)));
  220.  
  221.  
  222. }
  223.  
  224. public void sortByName() {
  225. for (int i = 1; i < supplies.length; i++) {
  226. int j;
  227. Product val = supplies[i];
  228. for (j = i - 1; j > -1; j--) {
  229. Product temp = supplies[j];
  230. if (temp.compareTo(val) <= 0) {
  231. break;
  232. }
  233. supplies[j + 1] = temp;
  234. }
  235. supplies[j + 1] = val;
  236. }
  237. }
  238.  
  239. //creates a String representation of the array of products
  240. public String toString() {
  241. String s = "";
  242. for (Product p : supplies) {
  243. s = s + p.toString();
  244. s = s + "\n\n";
  245. }
  246. return s;
  247. }
  248.  
  249. //Using an array so adding an item requires us to increase the size of the array first
  250. public void addProduct(Product p1) {
  251. if (supplies == null) {
  252. supplies = new Product[0];
  253. }
  254. Product[] p = supplies; //Copy all products into p first
  255. Product[] temp = new Product[p.length + 1]; //create bigger array
  256. for (int i = 0; i < p.length; i++) {
  257. temp[i] = p[i];
  258. }
  259. temp[(temp.length - 1)] = p1; //add the new product at the last position
  260. supplies = temp;
  261. }
  262.  
  263. //sorting the array using Bubble Sort
  264. public double calculateTotalInventory() {
  265. double total = 0.0;
  266. for (int i = 0; i < supplies.length; i++) {
  267. total = total + supplies[i].calculateInventoryValue();
  268. }
  269. return total;
  270. }
  271.  
  272. public void showInventory() {
  273. System.out.println(toString()); //call our toString method
  274. }
  275. }
here are the error msgs:
[TEX][Compiling 1 source file to C:\Documents and Settings\Bob Jefferson\My Documents\NetBeansProjects\Inventory4_4\build\classes
C:\Documents and Settings\Bob Jefferson\My Documents\NetBeansProjects\Inventory4_4\src\inventory4\Inventory4.java:201: duplicate class: inventory4.Inventory4
public class Inventory4 {
C:\Documents and Settings\Bob Jefferson\My Documents\NetBeansProjects\Inventory4_4\src\inventory4\Inventory4.java:8: inventory4.Inventory4 is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
public class Inventory4 extends JFrame implements ActionListener {
/TEX]
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Inventory graphics prob

 
0
  #2
May 31st, 2008
you have 2 classes with the same name in that package. That's not allowed.
Keep classes one to a sourcefile, much easier (and as in that case the file should have the name of the class you can't create more than one class with the same name per package any longer).

The other is clear. You define your class to implement an interface or abstract class but don't actually implement the methods you need to.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
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