Java: JavaFX: Unterschied zwischen den Versionen
Flinh1 (Diskussion | Beiträge) (→Links und Quellen) |
Flinh1 (Diskussion | Beiträge) (→Troubeshooting) |
||
| Zeile 51: | Zeile 51: | ||
---- | ---- | ||
| + | == Grundstruktur == | ||
| + | ===Imports === | ||
| + | <nowiki> | ||
| + | import javafx.application.Application; | ||
| + | import javafx.application.Platform; | ||
| + | import javafx.event.Event; | ||
| + | import javafx.scene.Scene; | ||
| + | import javafx.scene.control.Button; | ||
| + | import javafx.scene.layout.StackPane; | ||
| + | import javafx.stage.Stage;</nowiki> | ||
| + | |||
| + | ---- | ||
| + | === Beispiel === | ||
| + | <nowiki> | ||
| + | public class ErstesBeispiel extends Application { | ||
| + | @Override | ||
| + | public void init() { | ||
| + | System.out.println("init"); | ||
| + | } | ||
| + | @Override | ||
| + | public void start(Stage stage) { | ||
| + | System.out.println("start"); | ||
| + | StackPane pane = new StackPane(); | ||
| + | Button button = new Button(); | ||
| + | button.setText("Hier klicken"); | ||
| + | button.setOnAction(e -> Platform.exit()); | ||
| + | pane.getChildren().add(button); | ||
| + | stage.setScene(new Scene(pane, 400, 100)); | ||
| + | stage.setOnCloseRequest(Event::consume); | ||
| + | stage.setTitle("Erstes Beispiel"); | ||
| + | stage.setResizable(false); | ||
| + | stage.show(); | ||
| + | } | ||
| + | 456 28 Einführung in JavaFX | ||
| + | @Override | ||
| + | public void stop() { | ||
| + | System.out.println("stop"); | ||
| + | } | ||
| + | public static void main(String[] args) { | ||
| + | launch(args); | ||
| + | } | ||
| + | }</nowiki> | ||
| + | [https://www.springer.com/de/book/9783658304935 Abts, Dietmar: Grundkurs Java, 11. Auflage 2020] | ||
| + | |||
| + | ---- | ||
| + | |||
== Links und Quellen == | == Links und Quellen == | ||
Version vom 18. Februar 2021, 15:47 Uhr
Inhaltsverzeichnis
Allgemeines
Installation
Download von https://gluonhq.com/products/javafx/
zip-Paket entpacken, Laufwerk oder Ordner beliebig
In IntelliJ Idea
1. File -> Project Structure -> Libraries
Den lib Ordner des entpackten JavaFX einbinden.
2. In Edit Configurations VM Options eintragen:
Linux/MAC:
--module-path /path/to/javafx-sdk-15.0.1/lib --add-modules javafx.controls,javafx.fxml
(Padangabe anpassen)
Windows:
--module-path "\path\to\javafx-sdk-15.0.1\lib" --add-modules javafx.controls,javafx.fxml
(Padangabe anpassen)
Troubeshooting
module javafx.base not found
> Prüfen, ob in Run > Run Configuration > VM Options
der Pfad zum lib-Verzeichnis von JavaFX richtig gesetzt ist.
Grundstruktur
Imports
import javafx.application.Application; import javafx.application.Platform; import javafx.event.Event; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.stage.Stage;
Beispiel
public class ErstesBeispiel extends Application {
@Override
public void init() {
System.out.println("init");
}
@Override
public void start(Stage stage) {
System.out.println("start");
StackPane pane = new StackPane();
Button button = new Button();
button.setText("Hier klicken");
button.setOnAction(e -> Platform.exit());
pane.getChildren().add(button);
stage.setScene(new Scene(pane, 400, 100));
stage.setOnCloseRequest(Event::consume);
stage.setTitle("Erstes Beispiel");
stage.setResizable(false);
stage.show();
}
456 28 Einführung in JavaFX
@Override
public void stop() {
System.out.println("stop");
}
public static void main(String[] args) {
launch(args);
}
}
Abts, Dietmar: Grundkurs Java, 11. Auflage 2020
Links und Quellen
- https://wiki.openjdk.java.net/display/OpenJFX/Building+OpenJFX
- https://openjfx.io/javadoc/15/javafx.fxml/javafx/fxml/doc-files/introduction_to_fxml.html
- https://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/GridPane.html
- https://gluonhq.com/products/javafx/ Download
| |