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

BorderDecorator,shapeContainer

parent c93bd542
No related branches found
No related tags found
No related merge requests found
...@@ -23,18 +23,22 @@ public class App extends Application { ...@@ -23,18 +23,22 @@ public class App extends Application {
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
Group root = new Group(); Group root = new Group();
Canvas canvas = new Canvas(130, 110); Canvas canvas = new Canvas(260, 220);
GraphicsContext graphicsContext = canvas.getGraphicsContext2D(); GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
ShapeContainer shapeContainer = new ShapeContainer(); ShapeContainer shapeContainer = new ShapeContainer();
graphicsContext.setFill(Color.AQUAMARINE); graphicsContext.setFill(Color.AQUAMARINE);
graphicsContext.fillOval(10,10,10,10); graphicsContext.fillOval(10,10,10,10);
shapeContainer.addShape(new Rectangle(Color.BLUE,new Point2D(50,50), new Point2D(100,100))); Rectangle rectangle = new Rectangle(Color.BLUE,new Point2D(100,100), new Point2D(200,200));
shapeContainer.addShape(rectangle);
List<Point2D> points = new ArrayList<>(); List<Point2D> points = new ArrayList<>();
points.add(new Point2D(20,20)); points.add(new Point2D(10,10));
points.add(new Point2D(30,30)); points.add(new Point2D(100,40));
//points.add(new Point2D(80,80)); points.add(new Point2D(60,60));
points.add(new Point2D(40,100));
shapeContainer.addShape(new Polygon(Color.BLACK,points)); Polygon polygon = new Polygon(Color.BLACK,points);
shapeContainer.addShape(polygon);
BorderDecorator borderDecorator = new BorderDecorator(rectangle,10);
borderDecorator.drawDecoration(graphicsContext);
shapeContainer.draw(graphicsContext); shapeContainer.draw(graphicsContext);
root.getChildren().add(canvas); root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root)); primaryStage.setScene(new Scene(root));
......
...@@ -2,6 +2,7 @@ package shape; ...@@ -2,6 +2,7 @@ package shape;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -23,7 +24,7 @@ public class BorderDecorator extends Decorator{ ...@@ -23,7 +24,7 @@ public class BorderDecorator extends Decorator{
list.add(point(index)); list.add(point(index));
} }
for(Point2D point : list){ for(Point2D point : list){
graphicsContext.strokeOval(point.getX(),point.getY(),radius,radius); graphicsContext.fillOval(point.getX()-(radius/2),point.getY()-(radius/2),radius, radius);
} }
} }
} }
...@@ -17,4 +17,5 @@ public class ShapeContainer{ ...@@ -17,4 +17,5 @@ public class ShapeContainer{
for(Shape shape : shapes) for(Shape shape : shapes)
shape.draw(context); shape.draw(context);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment