Skip to content
Snippets Groups Projects
Rectangle.java 868 B
Newer Older
  • Learn to ignore specific revisions
  • BasileCouetoux's avatar
    BasileCouetoux committed
    package shape;
    
    import javafx.geometry.Point2D;
    import javafx.scene.canvas.GraphicsContext;
    import javafx.scene.paint.Color;
    
    
    public class Rectangle implements Shape{
    
        private double x;
        private double y;
        private double width;
        private double height;
    
        public Rectangle(double x, double y, double width, double height) {
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
    
    BasileCouetoux's avatar
    BasileCouetoux committed
        }
    
        @Override
    
        public void paint(GraphicsContext graphicsContext) {
            graphicsContext.strokeRect(x, y, width, height);
    
    BasileCouetoux's avatar
    BasileCouetoux committed
    
    
    BasileCouetoux's avatar
    BasileCouetoux committed
    
    
        @Override
        public boolean contains(double x, double y) {
            return x>= this.x && x<= this.x + this.width
                    && y>= this.y && y<= this.y + this.height;
        }
    
    BasileCouetoux's avatar
    BasileCouetoux committed
    
    
        @Override
        public void translate(double dx, double dy) {
            x += dx;
            y += dy;
    
    BasileCouetoux's avatar
    BasileCouetoux committed
        }
    }