Anchorpane

This commit is contained in:
Sage The DM 2024-10-29 09:46:04 +01:00
parent f3b770e972
commit 48a8902a52
13 changed files with 133 additions and 12 deletions

View file

@ -1,5 +1,5 @@
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
}
}§
}

View file

@ -2,29 +2,43 @@ package com.example;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
* JavaFX App
*/
public class App extends Application {
private Scene scene1, scene2;
@Override
public void start(Stage stage) {
var javaVersion = SystemInfo.javaVersion();
var javafxVersion = SystemInfo.javafxVersion();
// First scene with distinct text
Label label1 = new Label("Welcome to Scene 1!");
Button switchToScene2 = new Button("Switch to Scene 2");
VBox layout1 = new VBox(20, label1, switchToScene2); // VBox with spacing between elements
layout1.setStyle("-fx-alignment: center;"); // Center-align VBox contents
scene1 = new Scene(layout1, 640, 480);
var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
var scene = new Scene(new StackPane(label), 640, 480);
stage.setScene(scene);
// Second scene with distinct text
Label label2 = new Label("You are now in Scene 2!");
Button switchToScene1 = new Button("Switch to Scene 1");
VBox layout2 = new VBox(20, label2, switchToScene1); // VBox with spacing between elements
layout2.setStyle("-fx-alignment: center;"); // Center-align VBox contents
scene2 = new Scene(layout2, 640, 480);
// Button actions to switch scenes
switchToScene2.setOnAction(e -> stage.setScene(scene2));
switchToScene1.setOnAction(e -> stage.setScene(scene1));
// Set initial scene and show the stage
stage.setScene(scene1);
stage.setTitle("Scene Switcher");
stage.show();
}
public static void main(String[] args) {
launch();
}
}
}

View file

@ -0,0 +1,46 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>_05_layouts</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,44 @@
package com.example;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
/**
* JavaFX App with AnchorPane layout
*/
public class App extends Application {
@Override
public void start(Stage stage) {
// Create AnchorPane
AnchorPane anchorPane = new AnchorPane();
// Create Controll button
Button controlButton = new Button("Button");
AnchorPane.setTopAnchor(controlButton, 50.0);
AnchorPane.setLeftAnchor(controlButton, 50.0);
AnchorPane.setRightAnchor(controlButton, 10.0);
AnchorPane.setBottomAnchor(controlButton, 10.0);
// Create Button 1
Button button1 = new Button("Button 1");
AnchorPane.setTopAnchor(button1, 10.0);
AnchorPane.setLeftAnchor(button1, 10.0);
// Add buttons to the pane
anchorPane.getChildren().addAll(controlButton, button1);
// Set up the Scene with AnchorPane
Scene scene = new Scene(anchorPane, 640, 480);
stage.setTitle("Hauptfenster with AnchorPane");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}

View file

@ -0,0 +1,13 @@
package com.example;
public class SystemInfo {
public static String javaVersion() {
return System.getProperty("java.version");
}
public static String javafxVersion() {
return System.getProperty("javafx.version");
}
}

View file

@ -0,0 +1,4 @@
module com.example {
requires javafx.controls;
exports com.example;
}

Binary file not shown.