Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics2D;
- import javafx.scene.canvas.Canvas;
- import javafx.scene.canvas.GraphicsContext;
- import javafx.scene.paint.Color;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author student
- */
- public class Tree extends Canvas {
- GraphicsContext g2 = super.getGraphicsContext2D();
- public Tree() {
- super();
- setWidth(500);
- setHeight(500);
- draw(100, 250, 500, 250, 400);
- }
- public void draw(int n, double x1, double y1, double x2, double y2) {
- g2.setFill(Color.RED);
- g2.setLineWidth(2);
- int len = n;
- if (n > 1) {
- g2.strokeLine(x1, y1, x2, y2);
- len-=20;
- draw(len, x2, y2, x2 - len, y2-len);
- draw(len, x2, y2, x2 +len, y2-len);
- }
- }
- }
- *************************
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.layout.Pane;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Stage;
- /**
- *
- * @author student
- */
- public class z5 extends Application {
- @Override
- public void start(Stage primaryStage) {
- Pane root = new Pane();
- Label l = new Label("");
- root.getChildren().add(new Tree());
- Scene scene = new Scene(root, 500, 500);
- primaryStage.setTitle("COSMO");
- primaryStage.setScene(scene);
- primaryStage.show();
- primaryStage.setResizable(false);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement