Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- public class Block implements Locatable
- {
- private int xPos;
- private int yPos;
- private int width;
- private int height;
- private Color color;
- public Block()
- {
- xPos = 100;
- yPos = 150;
- width = 10;
- height = 10;
- color = new Color(0, 0, 0);
- }
- //add other Block constructors - x , y , width, height, color
- public Block(int x, int y)
- {
- xPos = x;
- yPos =y;
- width = 10;
- height = 10;
- color = new Color(0, 0, 0);
- }
- public Block(int x, int y, int wt, int ht)
- {
- xPos = x;
- yPos = y;
- width = wt;
- height = ht;
- color = new Color(0, 0, 0);
- }
- public Block(int x, int y, int wt, int ht,Color c)
- {
- xPos = x;
- yPos = y;
- width = wt;
- height = ht;
- color = c;
- }
- public void setX(int x)
- {
- xPos = x;
- }
- public void setY(int y)
- {
- yPos = y;
- }
- public void setWidth(int wt)
- {
- width = wt;
- }
- public void setHeight(int ht)
- {
- height = ht;
- }
- public void setPos(int x, int y)
- {
- xPos = x;
- yPos = y;
- }
- //add the other set methods
- public void setColor(Color col)
- {
- color = col;
- }
- public void draw(Graphics window)
- {
- //uncomment after you write the set and get methods
- window.setColor(color);
- window.fillRect(getX(), getY(), getWidth(), getHeight());
- }
- public void draw(Graphics window, Color col)
- {
- }
- public boolean equals(Object obj)
- {
- Block lhs = (Block) obj;
- if(this.getX()== lhs.getX() && this.getY() == lhs.getY() && this.getHeight() == lhs.getHeight() && this.getWidth() == lhs.getWidth() && this.getColor() == lhs.getColor())
- return true;
- return false;
- }
- //add the other get methods
- public int getX()
- {
- return xPos;
- }
- public int getY()
- {
- return yPos;
- }
- public int getWidth()
- {
- return width;
- }
- public int getHeight()
- {
- return height;
- }
- public Color getColor()
- {
- return color;
- }
- //add a toString() method - x , y , width, height, color
- public String toString()
- {
- return getX() + " " + getY() + " " + getWidth() + " " + getHeight() + " " + getColor();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement