Advertisement
Guest User

alexandra

a guest
Mar 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1.  
  2. import java.awt.Graphics2D;
  3. import javafx.scene.canvas.Canvas;
  4. import javafx.scene.canvas.GraphicsContext;
  5. import javafx.scene.paint.Color;
  6.  
  7. /*
  8. * To change this license header, choose License Headers in Project Properties.
  9. * To change this template file, choose Tools | Templates
  10. * and open the template in the editor.
  11. */
  12. /**
  13. *
  14. * @author student
  15. */
  16. public class Tree extends Canvas {
  17.  
  18. GraphicsContext g2 = super.getGraphicsContext2D();
  19.  
  20. public Tree() {
  21. super();
  22. setWidth(500);
  23. setHeight(500);
  24. draw(100, 250, 500, 250, 400);
  25. }
  26.  
  27. public void draw(int n, double x1, double y1, double x2, double y2) {
  28. g2.setFill(Color.RED);
  29. g2.setLineWidth(2);
  30. int len = n;
  31. if (n > 1) {
  32. g2.strokeLine(x1, y1, x2, y2);
  33. len-=20;
  34. draw(len, x2, y2, x2 - len, y2-len);
  35. draw(len, x2, y2, x2 +len, y2-len);
  36.  
  37. }
  38.  
  39. }
  40.  
  41. }
  42.  
  43. *************************
  44. /*
  45. * To change this license header, choose License Headers in Project Properties.
  46. * To change this template file, choose Tools | Templates
  47. * and open the template in the editor.
  48. */
  49.  
  50. import javafx.application.Application;
  51. import javafx.event.ActionEvent;
  52. import javafx.event.EventHandler;
  53. import javafx.scene.Scene;
  54. import javafx.scene.control.Button;
  55. import javafx.scene.control.Label;
  56. import javafx.scene.layout.Pane;
  57. import javafx.scene.layout.StackPane;
  58. import javafx.stage.Stage;
  59.  
  60. /**
  61. *
  62. * @author student
  63. */
  64. public class z5 extends Application {
  65.  
  66. @Override
  67. public void start(Stage primaryStage) {
  68. Pane root = new Pane();
  69. Label l = new Label("");
  70. root.getChildren().add(new Tree());
  71. Scene scene = new Scene(root, 500, 500);
  72.  
  73. primaryStage.setTitle("COSMO");
  74. primaryStage.setScene(scene);
  75. primaryStage.show();
  76. primaryStage.setResizable(false);
  77. }
  78.  
  79. /**
  80. * @param args the command line arguments
  81. */
  82. public static void main(String[] args) {
  83. launch(args);
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement