NickMeinholdItem v0.1


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package project;
  2.  
  3. import java.awt.Image;
  4. import java.io.File;
  5.  
  6. import javax.imageio.ImageIO;
  7.  
  8. /**
  9.  *
  10.  * @author Mihir
  11.  */
  12. public class Item {
  13.  
  14. private boolean visible;
  15. private String itemtype;
  16. private String tooltip;
  17. private String imgpath;
  18. // added these two for drawing the item (Nick)
  19. private Image image;
  20. private Position pos;
  21.  
  22. /** Creates a new instance of Item */
  23. public Item() {
  24. pos = new Position(); // added this so position is not null, otherwise throws null pointer exception (Nick)
  25. // please add super(); to all subclasses
  26. }
  27. // added copy constructor for creating a new item to add to the canvas_items array list (Nick)
  28. public Item(Item original) {
  29. this.visible = original.visible;
  30. this.itemtype = new String(original.itemtype);
  31. this.tooltip = new String(original.tooltip);
  32. this.imgpath = new String(original.imgpath);
  33. this.image = original.image;
  34. this.pos = new Position(original.pos);
  35. }
  36.  
  37. public boolean isVisible() {
  38. return visible;
  39. }
  40.  
  41. public void setVisible(boolean visible) {
  42. this.visible = visible;
  43. }
  44.  
  45. public String getItemtype() {
  46. return itemtype;
  47. }
  48.  
  49. public void setItemtype(String itemtype) {
  50. this.itemtype = itemtype;
  51. }
  52.  
  53. public String getTooltip() {
  54. return tooltip;
  55. }
  56.  
  57. public void setTooltip(String tooltip) {
  58. this.tooltip = tooltip;
  59. }
  60.  
  61. public String getImgpath() {
  62. return imgpath;
  63. }
  64.  
  65. public void setImgpath(String imgpath) {
  66. this.imgpath = imgpath;
  67. // added this so here so that it's needs to be called once (Nick)
  68. try{
  69. this.image = ImageIO.read(new File (imgpath));
  70. }
  71. catch(Exception e) {
  72. System.out.println("Problem reading iage path" + e);
  73. }
  74. }
  75. // added these next three methods to draw the item (Nick)
  76. public Image getImg() {
  77. return image;
  78. }
  79. public void setPos(int x, int y) {
  80. this.pos.x = x;
  81. this.pos.y = y;
  82. }
  83. Position getPos() {
  84. return this.pos;
  85. }
  86.  
  87. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.