Created
September 18, 2017 19:04
-
-
Save William-Lake/6a5e57a0babfe6b9cadfc3696a6f4600 to your computer and use it in GitHub Desktop.
JavaFX - VERY BASIC Sample application
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
package main; | |
import javafx.application.Application; | |
import javafx.event.ActionEvent; | |
import javafx.event.EventHandler; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.layout.StackPane; | |
import javafx.stage.Stage; | |
public class Main extends Application | |
{ | |
// *** SKELETON *** | |
Scene scene; // The primary "Window", which according to JavaFX is a "Scene". | |
StackPane layout; // The layout which holds all the components. | |
// *** COMPONENTS *** | |
Button button; // Only necessary for this example. | |
/** | |
* Main Method to launch the application. | |
*/ | |
public static void main(String[] args) | |
{ | |
launch(args); // Part of the Application class. | |
} | |
@Override | |
public void start(Stage primaryStage) | |
{ | |
primaryStage.setTitle("The window/stage titlebar text"); | |
// *** INSTANTIATE *** | |
layout = new StackPane(); | |
button = new Button(); | |
// *** SET TEXT *** | |
button.setText("Click Me"); // Can also be passed as a parameter to the Button Constructor. | |
// *** LISTENERS *** | |
button.setOnAction(new EventHandler<ActionEvent>() | |
{ | |
@Override | |
public void handle(ActionEvent event) | |
{ | |
System.out.println("Button clicked."); | |
} | |
}); | |
// *** LAYOUT *** | |
layout.getChildren().add(button); | |
// *** CREATE *** | |
scene = new Scene(layout,300,250); // Window dimensions being passed in here. | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment