Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package trial;
- import javafx.application.Application;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.canvas.Canvas;
- import javafx.scene.canvas.GraphicsContext;
- import javafx.scene.layout.Pane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.ArcType;
- import javafx.scene.shape.Circle;
- import javafx.scene.shape.Line;
- import javafx.scene.shape.Polygon;
- import javafx.scene.shape.Rectangle;
- import javafx.stage.Stage;
- public class firstguipaint extends Application {
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void start(Stage primaryStage) {
- primaryStage.setTitle("Drawing Operations Test");
- Group root = new Group();
- Canvas canvas = new Canvas(300, 250);
- GraphicsContext gc = canvas.getGraphicsContext2D();
- GraphicsContext square = canvas.getGraphicsContext2D();
- drawShapes(gc);
- drawtest(square);
- root.getChildren().add(canvas);
- // Pane root = new Pane();
- //
- // Rectangle rect = createDraggableRectangle(200, 200, 400, 300);
- // rect.setFill(Color.NAVY);
- //
- // root.getChildren().add(rect);
- //
- //
- // Scene scene = new Scene(root, 800, 800);
- // primaryStage.setScene(scene);
- // primaryStage.show();
- Polygon polygon = new Polygon();
- polygon.getPoints().addAll(new Double[]{0.0, 0.0,0.0, 20.0, 20.0, 20.0,20.0, 0.0});
- Rectangle rect = new Rectangle(50, 50, 20, 30);
- root.getChildren().addAll(polygon,rect);
- primaryStage.setScene(new Scene(root));
- primaryStage.show();
- }
- private void drawtest(GraphicsContext square) {
- square.setStroke(Color.BLACK); // border color all shapes
- square.setLineWidth(10); // border width
- square.strokeLine(50, 50, 500, 500); //draw line
- }
- private void drawShapes(GraphicsContext gc) {
- //gc.setFill(Color.GREEN); // color of the shape all shapes
- gc.setFill(Color.BLUEVIOLET);
- gc.setStroke(Color.BLUE); // border color all shapes
- gc.setLineWidth(5); // border width
- gc.strokeLine(0, 0, 50, 50); //draw line
- gc.fillOval(10, 60, 30, 30); // draw oval shape (x,y,width, hight)
- //if hight = width => circle
- gc.strokeOval(60, 60, 30, 30); // without fill color
- gc.fillRoundRect(110, 60, 30, 30, 10, 10);
- gc.strokeRoundRect(160, 60, 30, 30, 10, 10);
- gc.fillArc(10, 110, 30, 30, 45, 240, ArcType.OPEN);
- gc.fillArc(60, 110, 30, 30, 45, 240, ArcType.CHORD);
- gc.fillArc(110, 110, 30, 30, 45, 240, ArcType.ROUND);
- gc.strokeArc(10, 160, 30, 30, 45, 240, ArcType.OPEN);
- gc.strokeArc(60, 160, 30, 30, 45, 240, ArcType.CHORD);
- gc.strokeArc(110, 160, 30, 30, 45, 240, ArcType.ROUND);
- gc.fillPolygon(new double[]{10, 40, 10, 40},
- new double[]{210, 210, 240, 240}, 4);
- gc.strokePolygon(new double[]{60, 90, 60, 90},
- new double[]{210, 210, 240, 240}, 4);
- gc.strokePolyline(new double[]{110, 140, 110, 140},
- new double[]{210, 210, 240, 240}, 4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement