Skip to content

Instantly share code, notes, and snippets.

@William-Lake
Created September 18, 2017 19:04
Show Gist options
  • Save William-Lake/6a5e57a0babfe6b9cadfc3696a6f4600 to your computer and use it in GitHub Desktop.
Save William-Lake/6a5e57a0babfe6b9cadfc3696a6f4600 to your computer and use it in GitHub Desktop.
JavaFX - VERY BASIC Sample application
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