Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- public class MovingRectangle{
- private Point topLeft;
- private int width;
- private int height;
- private Color borderColor;
- private Color fillColor;
- public MovingRectangle(Point topLeft, int width, int height, Color borderColor, Color fillColor){
- this.topLeft = topLeft;
- this.width = width;
- this.height = height;
- this.borderColor = borderColor;
- this.fillColor = fillColor;
- }
- public MovingRectangle(){
- this.topLeft = new Point(0,0);
- this.width = 10;
- this.height = 10;
- this.borderColor = Color.blue;
- this.fillColor = Color.black;
- }
- //getters
- public int getX(){
- return this.topLeft.x;
- }
- public int getY(){
- return this.topLeft.y;
- }
- public void setX(int x){
- this.topLeft.x = x;
- }
- public int getWidth(){
- return width;
- }
- public int getHeight(){
- return height;
- }
- //setters
- public void setY(int y){
- this.topLeft.y = y;
- }
- public void move(){
- this.topLeft.x = getX() + 1;
- this.topLeft.y = getY() + 2;
- }
- public boolean contains( Point p){//recatngel coitannts point
- return (this.topLeft.getX() < p.getX() && this.topLeft.getY() < p.getY() &&
- this.topLeft.getX() + this.getWidth() > p.getX() &&
- this.topLeft.getY() + this.getHeight() > p.getY());
- }
- public String toString(){
- return "(" + String.valueOf(getX()) + ", " + String.valueOf(getY())+ ")" + ", " + String.valueOf(width) + " x " + String.valueOf(height);
- }
- public static void main(String [] args){
- MovingRectangle r = new MovingRectangle(new Point(10, 20), 30, 40, Color.yellow, Color.orange);
- System.out.println(r);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement