First example to test component solution, renamed projects to neitzelfx.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package de.neitzel.neitzelfx.component.example;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Address {
|
||||
private String street;
|
||||
private String city;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package de.neitzel.neitzelfx.component.example;
|
||||
|
||||
import de.neitzel.neitzelfx.component.ComponentLoader;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class ExampleApp extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
// Beispielmodel initialisieren
|
||||
Address address = new Address();
|
||||
address.setStreet("Sample Street 1");
|
||||
address.setCity("Sample City");
|
||||
|
||||
Person person = new Person();
|
||||
person.setName("Max Mustermann");
|
||||
person.setAddress(address);
|
||||
|
||||
// ComponentLoader verwenden
|
||||
ComponentLoader loader = new ComponentLoader();
|
||||
Parent root = loader.load(person, "/person.fxml");
|
||||
|
||||
// Scene erstellen und anzeigen
|
||||
Scene scene = new Scene(root);
|
||||
primaryStage.setTitle("ComponentLoader Example");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package de.neitzel.neitzelfx.component.example;
|
||||
|
||||
import de.neitzel.neitzelfx.injectfx.example.JavaFXApp;
|
||||
|
||||
/**
|
||||
* Another Main class as workaround when the JavaFX Application ist started without
|
||||
* taking care os Classloader Requirements of JavaFX. (Important when starting from inside NetBeans!)
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* Additional main methode to start Application.
|
||||
* @param args Commandline Arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
ExampleApp.main(args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package de.neitzel.neitzelfx.component.example;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Person {
|
||||
private String name;
|
||||
private Address address;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package de.neitzel.neitzelfx.injectfx.example;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class JavaFXApp extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
try {
|
||||
primaryStage.setTitle("Hello World!");
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
|
||||
Parent root = fxmlLoader.load();
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.show();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Exception: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package de.neitzel.neitzelfx.injectfx.example;
|
||||
|
||||
/**
|
||||
* Another Main class as workaround when the JavaFX Application ist started without
|
||||
* taking care os Classloader Requirements of JavaFX. (Important when starting from inside NetBeans!)
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* Additional main methode to start Application.
|
||||
* @param args Commandline Arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
JavaFXApp.main(args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.neitzel.neitzelfx.injectfx.example;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.TextField;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class MainWindow implements Initializable {
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
@FXML
|
||||
private TextField textField;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
displayCounter();
|
||||
}
|
||||
|
||||
private void displayCounter() {
|
||||
textField.setText("Click counter: " + counter);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onButtonClick(ActionEvent actionEvent) {
|
||||
counter++;
|
||||
displayCounter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
xmlns:nfx="http://example.com/nfx"
|
||||
fx:controller="de.neitzel.neitzelfx.component.ComponentController"
|
||||
prefWidth="300" prefHeight="100">
|
||||
<children>
|
||||
<TextField layoutX="10" layoutY="10" prefWidth="280"
|
||||
nfx:target="street" nfx:direction="bidirectional"/>
|
||||
<TextField layoutX="10" layoutY="50" prefWidth="280"
|
||||
nfx:target="city" nfx:direction="bidirectional"/>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane prefHeight="127.0" prefWidth="209.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.neitzel.neitzelfx.injectfx.example.MainWindow">
|
||||
<children>
|
||||
<Button fx:id="button" layoutX="44.0" layoutY="70.0" mnemonicParsing="false" onAction="#onButtonClick" text="Click Me" />
|
||||
<TextField fx:id="textField" layoutX="14.0" layoutY="24.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
xmlns:nfx="http://example.com/nfx"
|
||||
fx:controller="de.neitzel.neitzelfx.component.ComponentController"
|
||||
prefWidth="300" prefHeight="180">
|
||||
<children>
|
||||
<TextField layoutX="10" layoutY="10" prefWidth="280"
|
||||
nfx:target="name" nfx:direction="bidirectional"/>
|
||||
<Pane layoutX="10" layoutY="50" prefWidth="280" prefHeight="110"
|
||||
nfx:target="address" nfx:direction="bidirectional"
|
||||
nfx:source="/address.fxml"/>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
Reference in New Issue
Block a user