1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void init() {
System.out.println("Initialization (init())");
}
@Override
public void start(Stage mainStage) {
System.out.println("Running (start(Stage))");
// Title of the window
mainStage.setTitle("My First JavaFX App");
// Start by building the "Hello JavaFX" button
Button btnHello = new Button("Hello JavaFX");
// It can be resized, and we can add a background and a border (inherit from Region)
//btnHello.setPrefSize(120,80);
btnHello.setBorder(new Border(new BorderStroke(Color.DARKRED, BorderStrokeStyle.SOLID, null, new BorderWidths(5))));
btnHello.setPadding(new Insets(20,50,40,100));
// Define the main container (e.g. any layout-pane) and add the button
BorderPane root = new BorderPane();
root.setCenter(btnHello);
// Build the Scene by giving the root pane
Scene scene = new Scene(root, 250, 100);
// Finally, set the Scene in the Stage and show the window
mainStage.setScene(scene);
mainStage.show();
}
@Override
public void stop() {
System.out.println("Closing (stop())");
}
public static void main(String[] args) {
launch(args);
}
} |