Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. import java.awt.*;
  2.     public class MovingRectangle{
  3.         private Point topLeft;
  4.         private int width;
  5.         private int height;
  6.         private Color borderColor;
  7.         private Color fillColor;
  8.  
  9.         public MovingRectangle(Point topLeft, int width, int height, Color borderColor, Color fillColor){
  10.             this.topLeft = topLeft;
  11.             this.width = width;
  12.             this.height = height;
  13.             this.borderColor = borderColor;
  14.             this.fillColor = fillColor;
  15.         }
  16.  
  17.  
  18.  
  19.         public MovingRectangle(){
  20.             this.topLeft = new Point(0,0);
  21.             this.width = 10;
  22.             this.height = 10;
  23.             this.borderColor = Color.blue;
  24.             this.fillColor = Color.black;
  25.  
  26.         }
  27.         //getters
  28.         public int getX(){
  29.             return this.topLeft.x;
  30.         }
  31.  
  32.         public int getY(){
  33.             return this.topLeft.y;
  34.         }
  35.  
  36.         public void setX(int x){
  37.             this.topLeft.x  = x;
  38.  
  39.         }
  40.  
  41.         public int getWidth(){
  42.             return width;
  43.         }
  44.  
  45.         public int getHeight(){
  46.             return height;
  47.         }
  48.  
  49.         //setters
  50.  
  51.         public void setY(int y){
  52.             this.topLeft.y = y;
  53.         }
  54.  
  55.         public void move(){
  56.             this.topLeft.x = getX() + 1;
  57.             this.topLeft.y = getY() + 2;
  58.    
  59.         }
  60.  
  61.         public boolean contains( Point p){//recatngel coitannts point
  62.              return (this.topLeft.getX() < p.getX() && this.topLeft.getY() < p.getY() &&
  63.                 this.topLeft.getX() + this.getWidth() > p.getX()  &&
  64.                 this.topLeft.getY() + this.getHeight() > p.getY());
  65.  
  66.         }
  67.  
  68.     public String toString(){
  69.         return "(" + String.valueOf(getX()) + ", " + String.valueOf(getY())+ ")" + ", " + String.valueOf(width) + " x " + String.valueOf(height);
  70.     }
  71.  
  72.     public static void main(String [] args){
  73.         MovingRectangle r = new MovingRectangle(new Point(10, 20), 30, 40, Color.yellow, Color.orange);
  74.         System.out.println(r);
  75.    
  76.  
  77.    
  78.     }
  79.  
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement