Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.geometry.Pos;
- import javafx.application.Application;
- import javafx.scene.*;
- import javafx.scene.paint.*;
- import javafx.scene.canvas.*;
- import javafx.scene.control.Label;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Stage;
- import javafx.scene.control.Button;
- public class Main extends Application {
- @Override
- public void start(Stage stage) {
- gc = canvas.getGraphicsContext2D();
- gc.setStroke(Color.BLACK);
- gc.setLineWidth(3);
- scene.setOnMousePressed(e->{
- gc.beginPath();
- gc.lineTo(e.getSceneX(),e.getSceneY()-300);
- gc.stroke();
- });
- scene.setOnMouseDragged(e->{
- gc.lineTo(e.getSceneX(),e.getSceneY()-300);
- gc.stroke();
- });
- b1.setStyle("-fx-font-size: 30; -fx-border-color: black;");
- canvas.setStyle("-fx-border-style: solid; -fx-border-width: 2;");
- pane.setAlignment(Pos.TOP_CENTER);
- pane.getChildren().add(b1);
- drawing.getChildren().add(canvas);
- drawing.setAlignment(Pos.BOTTOM_CENTER);
- drawing.setStyle("-fx-border-color: black;");
- pane.getChildren().add(drawing);
- stage.setScene(scene);
- stage.setResizable(false);
- stage.show();
- }
- Button b1 = new Button("SAVE IMAGE");
- Canvas canvas = new Canvas(800,500);
- GraphicsContext gc;
- StackPane pane = new StackPane();
- StackPane drawing = new StackPane();
- Scene scene = new Scene(pane,800,800);
- public static void main(String[] args) {
- launch();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement