Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import javafx.geometry.Pos;
  2. import javafx.application.Application;
  3. import javafx.scene.*;
  4. import javafx.scene.paint.*;
  5. import javafx.scene.canvas.*;
  6. import javafx.scene.control.Label;
  7. import javafx.scene.layout.StackPane;
  8. import javafx.stage.Stage;
  9. import javafx.scene.control.Button;
  10.  
  11.  
  12. public class Main extends Application {
  13.  
  14. @Override
  15. public void start(Stage stage) {
  16. gc = canvas.getGraphicsContext2D();
  17. gc.setStroke(Color.BLACK);
  18. gc.setLineWidth(3);
  19.  
  20. scene.setOnMousePressed(e->{
  21. gc.beginPath();
  22. gc.lineTo(e.getSceneX(),e.getSceneY()-300);
  23. gc.stroke();
  24. });
  25.  
  26. scene.setOnMouseDragged(e->{
  27. gc.lineTo(e.getSceneX(),e.getSceneY()-300);
  28. gc.stroke();
  29. });
  30.  
  31.  
  32. b1.setStyle("-fx-font-size: 30; -fx-border-color: black;");
  33. canvas.setStyle("-fx-border-style: solid; -fx-border-width: 2;");
  34.  
  35. pane.setAlignment(Pos.TOP_CENTER);
  36. pane.getChildren().add(b1);
  37. drawing.getChildren().add(canvas);
  38. drawing.setAlignment(Pos.BOTTOM_CENTER);
  39. drawing.setStyle("-fx-border-color: black;");
  40. pane.getChildren().add(drawing);
  41.  
  42.  
  43.  
  44. stage.setScene(scene);
  45. stage.setResizable(false);
  46. stage.show();
  47. }
  48.  
  49. Button b1 = new Button("SAVE IMAGE");
  50. Canvas canvas = new Canvas(800,500);
  51. GraphicsContext gc;
  52. StackPane pane = new StackPane();
  53. StackPane drawing = new StackPane();
  54. Scene scene = new Scene(pane,800,800);
  55.  
  56. public static void main(String[] args) {
  57. launch();
  58. }
  59.  
  60.  
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement