Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. package trial;
  2.  
  3.  
  4. import javafx.application.Application;
  5. import javafx.scene.Group;
  6. import javafx.scene.Scene;
  7. import javafx.scene.canvas.Canvas;
  8. import javafx.scene.canvas.GraphicsContext;
  9. import javafx.scene.layout.Pane;
  10. import javafx.scene.paint.Color;
  11. import javafx.scene.shape.ArcType;
  12. import javafx.scene.shape.Circle;
  13. import javafx.scene.shape.Line;
  14. import javafx.scene.shape.Polygon;
  15. import javafx.scene.shape.Rectangle;
  16. import javafx.stage.Stage;
  17.  
  18. public class firstguipaint extends Application {
  19.  
  20. public static void main(String[] args) {
  21. launch(args);
  22. }
  23.  
  24. @Override
  25. public void start(Stage primaryStage) {
  26. primaryStage.setTitle("Drawing Operations Test");
  27. Group root = new Group();
  28. Canvas canvas = new Canvas(300, 250);
  29. GraphicsContext gc = canvas.getGraphicsContext2D();
  30. GraphicsContext square = canvas.getGraphicsContext2D();
  31. drawShapes(gc);
  32. drawtest(square);
  33. root.getChildren().add(canvas);
  34.  
  35. // Pane root = new Pane();
  36. //
  37. // Rectangle rect = createDraggableRectangle(200, 200, 400, 300);
  38. // rect.setFill(Color.NAVY);
  39. //
  40. // root.getChildren().add(rect);
  41. //
  42. //
  43. // Scene scene = new Scene(root, 800, 800);
  44. // primaryStage.setScene(scene);
  45. // primaryStage.show();
  46.  
  47. Polygon polygon = new Polygon();
  48. polygon.getPoints().addAll(new Double[]{0.0, 0.0,0.0, 20.0, 20.0, 20.0,20.0, 0.0});
  49.  
  50. Rectangle rect = new Rectangle(50, 50, 20, 30);
  51.  
  52. root.getChildren().addAll(polygon,rect);
  53.  
  54. primaryStage.setScene(new Scene(root));
  55. primaryStage.show();
  56. }
  57.  
  58. private void drawtest(GraphicsContext square) {
  59. square.setStroke(Color.BLACK); // border color all shapes
  60. square.setLineWidth(10); // border width
  61. square.strokeLine(50, 50, 500, 500); //draw line
  62.  
  63. }
  64.  
  65. private void drawShapes(GraphicsContext gc) {
  66. //gc.setFill(Color.GREEN); // color of the shape all shapes
  67. gc.setFill(Color.BLUEVIOLET);
  68. gc.setStroke(Color.BLUE); // border color all shapes
  69. gc.setLineWidth(5); // border width
  70. gc.strokeLine(0, 0, 50, 50); //draw line
  71. gc.fillOval(10, 60, 30, 30); // draw oval shape (x,y,width, hight)
  72. //if hight = width => circle
  73. gc.strokeOval(60, 60, 30, 30); // without fill color
  74. gc.fillRoundRect(110, 60, 30, 30, 10, 10);
  75. gc.strokeRoundRect(160, 60, 30, 30, 10, 10);
  76. gc.fillArc(10, 110, 30, 30, 45, 240, ArcType.OPEN);
  77. gc.fillArc(60, 110, 30, 30, 45, 240, ArcType.CHORD);
  78. gc.fillArc(110, 110, 30, 30, 45, 240, ArcType.ROUND);
  79. gc.strokeArc(10, 160, 30, 30, 45, 240, ArcType.OPEN);
  80. gc.strokeArc(60, 160, 30, 30, 45, 240, ArcType.CHORD);
  81. gc.strokeArc(110, 160, 30, 30, 45, 240, ArcType.ROUND);
  82. gc.fillPolygon(new double[]{10, 40, 10, 40},
  83. new double[]{210, 210, 240, 240}, 4);
  84. gc.strokePolygon(new double[]{60, 90, 60, 90},
  85. new double[]{210, 210, 240, 240}, 4);
  86. gc.strokePolyline(new double[]{110, 140, 110, 140},
  87. new double[]{210, 210, 240, 240}, 4);
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement