Created
February 14, 2020 14:36
-
-
Save HanSolo/db5301641cadb7aaa4e2d258acb111d3 to your computer and use it in GitHub Desktop.
GalaxyFX (Template for a simple JavaFX application with a Canvas node)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.scene.canvas.Canvas; | |
import javafx.scene.canvas.GraphicsContext; | |
import javafx.scene.paint.Color; | |
import javafx.stage.Stage; | |
import javafx.scene.layout.StackPane; | |
import javafx.scene.Scene; | |
/** | |
* User: hansolo | |
* Date: 14.02.20 | |
* Time: 14:58 | |
*/ | |
public class Main extends Application { | |
private Canvas canvas; | |
private GraphicsContext ctx; | |
@Override public void init() { | |
canvas = new Canvas(500, 800); | |
ctx = canvas.getGraphicsContext2D(); | |
} | |
@Override public void start(Stage stage) { | |
StackPane pane = new StackPane(canvas); | |
Scene scene = new Scene(pane); | |
stage.setTitle("GalaxyFX"); | |
stage.setScene(scene); | |
stage.show(); | |
draw(ctx); | |
} | |
@Override public void stop() { | |
System.exit(0); | |
} | |
private void draw(final GraphicsContext ctx) { | |
ctx.clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); | |
ctx.setStroke(Color.RED); | |
ctx.strokeLine(10, 10, 200, 200); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment