/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// added picked() method that returns true if the item was selected with a mouse click package project; import java.awt.Image; import java.io.File; import javax.imageio.ImageIO; /** * * @author Mihir */ public class Item { private boolean visible; // added these two for drawing the item (Nick) /** Creates a new instance of Item */ public Item() { pos = new Position(); // added this so position is not null, otherwise throws null pointer exception (Nick) // please add super(); to all subclasses } // added copy constructor for creating a new item to add to the canvas_items array list (Nick) public Item(Item original) { this.visible = original.visible; this.image = original.image; } public boolean isVisible() { return visible; } public void setVisible(boolean visible) { this.visible = visible; } return itemtype; } this.itemtype = itemtype; } return tooltip; } this.tooltip = tooltip; } return imgpath; } this.imgpath = imgpath; // added this so here so that it's needs to be called once (Nick) try{ } } } // added these next three methods to draw the item (Nick) return image; } public void setPos(int x, int y) { this.pos.x = x; this.pos.y = y; } return this.pos; } boolean picked(int x, int y) { if(x > this.pos.x && x < (this.pos.x+image.getWidth(null)) && y > this.pos.y && y < (this.pos.y+image.getHeight(null))) return true; else return false; } }