Workshop durchgeführt.
This commit is contained in:
parent
2c9c8dd225
commit
af901a38fc
|
@ -21,3 +21,9 @@
|
|||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
# Ignore Gradle project-specific cache directory
|
||||
.gradle
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
id 'application'
|
||||
id 'org.openjfx.javafxplugin' version '0.0.12'
|
||||
}
|
||||
javafx {
|
||||
version = '17'
|
||||
modules = [ 'javafx.controls', 'javafx.fxml' ]
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
*/
|
||||
package ch.zhaw.prog2.application;
|
||||
|
||||
public class App {
|
||||
public String getGreeting() {
|
||||
return "Hello World!";
|
||||
}
|
||||
import javafx.application.Application;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new App().getGreeting());
|
||||
Application.launch(MainWindow.class, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package ch.zhaw.prog2.application;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class MainWindow extends Application {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
openMainWindow(primaryStage);
|
||||
}
|
||||
|
||||
private void openMainWindow(Stage stage) {
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
|
||||
|
||||
Pane rootNode = loader.load();
|
||||
|
||||
MainWindowController mainWindowController = loader.getController();
|
||||
//mainWindowController.connectProperties(); //nicht benötigt, da in der Methode MainWindowController in initialize aufgerufen wird.
|
||||
|
||||
|
||||
Scene scene = new Scene(rootNode);
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package ch.zhaw.prog2.application;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
|
||||
public class MainWindowController {
|
||||
|
||||
public void initialize(){
|
||||
connectProperties();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private Label labelTitel;
|
||||
|
||||
@FXML
|
||||
private TextField textEingabe;
|
||||
|
||||
@FXML
|
||||
private TextArea textHistory;
|
||||
|
||||
@FXML
|
||||
void hinzufuegenText(ActionEvent event) {
|
||||
String text = textHistory.getText();
|
||||
text += textEingabe.getText() + "\n";
|
||||
textHistory.setText(text);
|
||||
textEingabe.clear();
|
||||
}
|
||||
|
||||
@FXML
|
||||
void leerenTextEingabe(ActionEvent event) {
|
||||
textEingabe.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void connectProperties() {
|
||||
// erste Möglichkeit
|
||||
labelTitel.textProperty().bind(textEingabe.textProperty());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<AnchorPane prefHeight="480.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.prog2.application.MainWindowController">
|
||||
<children>
|
||||
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" spacing="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<Label fx:id="labelTitel" text="Label" />
|
||||
<TextField fx:id="textEingabe" maxWidth="300.0" />
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="10.0">
|
||||
<children>
|
||||
<Button mnemonicParsing="false" onAction="#hinzufuegenText" text="Hinzufügen Text" />
|
||||
<Button mnemonicParsing="false" onAction="#leerenTextEingabe" text="Löschen Eingabefeld" />
|
||||
</children>
|
||||
</HBox>
|
||||
<TextArea fx:id="textHistory" editable="false" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets top="10.0" />
|
||||
</padding>
|
||||
</VBox>
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="20.0" />
|
||||
</padding>
|
||||
</AnchorPane>
|
Loading…
Reference in New Issue