Anchorpane
This commit is contained in:
		
							parent
							
								
									f3b770e972
								
							
						
					
					
						commit
						48a8902a52
					
				
					 13 changed files with 133 additions and 12 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							|  | @ -1,5 +1,5 @@ | ||||||
| public class App { | public class App { | ||||||
|     public static void main(String[] args) throws Exception { |     public static void main(String[] args) throws Exception { | ||||||
|         System.out.println("Hello, World!"); |         System.out.println("Hello, World!"); | ||||||
|     } |     }§ | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,29 +2,43 @@ package com.example; | ||||||
| 
 | 
 | ||||||
| import javafx.application.Application; | import javafx.application.Application; | ||||||
| import javafx.scene.Scene; | import javafx.scene.Scene; | ||||||
|  | import javafx.scene.control.Button; | ||||||
| import javafx.scene.control.Label; | import javafx.scene.control.Label; | ||||||
| import javafx.scene.layout.StackPane; | import javafx.scene.layout.StackPane; | ||||||
|  | import javafx.scene.layout.VBox; | ||||||
| import javafx.stage.Stage; | import javafx.stage.Stage; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * JavaFX App |  | ||||||
|  */ |  | ||||||
| public class App extends Application { | public class App extends Application { | ||||||
| 
 | 
 | ||||||
|  |     private Scene scene1, scene2; | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void start(Stage stage) { |     public void start(Stage stage) { | ||||||
|         var javaVersion = SystemInfo.javaVersion(); |         // First scene with distinct text | ||||||
|         var javafxVersion = SystemInfo.javafxVersion(); |         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 + "."); |         // Second scene with distinct text | ||||||
|         var scene = new Scene(new StackPane(label), 640, 480); |         Label label2 = new Label("You are now in Scene 2!"); | ||||||
|         stage.setScene(scene); |         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(); |         stage.show(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static void main(String[] args) { |     public static void main(String[] args) { | ||||||
|         launch(); |         launch(); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
| } | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								Code/ost/_04_several_scenes/target/classes/com/example/App.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/ost/_04_several_scenes/target/classes/com/example/App.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Code/ost/_04_several_scenes/target/classes/module-info.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/ost/_04_several_scenes/target/classes/module-info.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										46
									
								
								Code/ost/_05_layouts/pom.xml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								Code/ost/_05_layouts/pom.xml
									
										
									
									
									
										Normal 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> | ||||||
							
								
								
									
										44
									
								
								Code/ost/_05_layouts/src/main/java/com/example/App.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								Code/ost/_05_layouts/src/main/java/com/example/App.java
									
										
									
									
									
										Normal 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(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -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"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										4
									
								
								Code/ost/_05_layouts/src/main/java/module-info.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								Code/ost/_05_layouts/src/main/java/module-info.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | ||||||
|  | module com.example { | ||||||
|  |     requires javafx.controls; | ||||||
|  |     exports com.example; | ||||||
|  | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								Code/ost/_05_layouts/target/classes/com/example/App.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/ost/_05_layouts/target/classes/com/example/App.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Code/ost/_05_layouts/target/classes/com/example/SystemInfo.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/ost/_05_layouts/target/classes/com/example/SystemInfo.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Code/ost/_05_layouts/target/classes/module-info.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/ost/_05_layouts/target/classes/module-info.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sage The DM
						Sage The DM