Skip to content
Snippets Groups Projects
Commit c93bd542 authored by 1380's avatar 1380
Browse files

Some modifications

parent 4a9193b8
No related branches found
No related tags found
No related merge requests found
......@@ -3,23 +3,28 @@ package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import java.util.ArrayList;
import java.util.List;
public abstract class AbstractShape implements Shape {
private List<Point2D> points;
public AbstractShape(){
this.points = new ArrayList<>();
}
@Override
public int pointsCount() {
return points.size();
return this.points.size();
}
@Override
public Point2D point(int index) {
return points.get(index);
return this.points.get(index);
}
@Override
abstract public void draw(GraphicsContext context) ;
public void addPoints(List<Point2D> points) {
points.addAll(points);
this.points.addAll(points);
}
}
......@@ -10,6 +10,8 @@ import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.List;
public class App extends Application {
......@@ -26,7 +28,13 @@ public class App extends Application {
ShapeContainer shapeContainer = new ShapeContainer();
graphicsContext.setFill(Color.AQUAMARINE);
graphicsContext.fillOval(10,10,10,10);
shapeContainer.addShape(new Rectangle(Color.BLUE,new Point2D(10,10), new Point2D(40,40)));
shapeContainer.addShape(new Rectangle(Color.BLUE,new Point2D(50,50), new Point2D(100,100)));
List<Point2D> points = new ArrayList<>();
points.add(new Point2D(20,20));
points.add(new Point2D(30,30));
//points.add(new Point2D(80,80));
shapeContainer.addShape(new Polygon(Color.BLACK,points));
shapeContainer.draw(graphicsContext);
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
......
......@@ -19,5 +19,11 @@ public class BorderDecorator extends Decorator{
@Override
protected void drawDecoration(GraphicsContext graphicsContext) {
List<Point2D> list = new ArrayList<>();
for(int index = 0 ; index<pointsCount() ; index++){
list.add(point(index));
}
for(Point2D point : list){
graphicsContext.strokeOval(point.getX(),point.getY(),radius,radius);
}
}
}
package shape;
import javafx.scene.canvas.GraphicsContext;
public class CenterDecorator extends Decorator {
double radius;
public CenterDecorator(Shape decoratedShape, double radius) {
super(decoratedShape);
this.radius = radius;
}
@Override
protected void drawDecoration(GraphicsContext graphicsContext) {
}
}
......@@ -3,19 +3,10 @@ package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
public class Circle implements Shape {
public class Circle extends AbstractShape implements Shape {
public Circle(double x, double y, double sqrt) {
}
@Override
public int pointsCount() {
return 0;
}
@Override
public Point2D point(int index) {
return null;
}
@Override
......
......@@ -23,6 +23,7 @@ public class Polygon extends AbstractShape {
coordinateX[index]=point(index).getX();
coordinateY[index]=point(index).getY();
}
context.strokePolygon(coordinateX,coordinateY,pointsCount());
context.setFill(color);
context.fillPolygon(coordinateX,coordinateY,pointsCount());
}
}
......@@ -19,7 +19,9 @@ public class Rectangle extends AbstractShape implements Shape{
@Override
public void draw(GraphicsContext context) {
context.strokeRect(point(0).getX(),point(0).getY(),point(1).getX()-point(0).getX(),
point(1).getY()-point(0).getY());
context.setFill(color);
context.fillRect(point(0).getX(),point(0).getY(),(point(1).getX())-(point(0).getX()),
(point(1).getY())-(point(0).getY()));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment