import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.Separator; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.GridPane; import javafx.scene.text.Text; import javafx.stage.Stage; import java.sql.*; public class Marks extends Application { private GridPane grid; private Text status; private Connection connection; @Override public void start(Stage stage) { this.grid = new GridPane(); this.createStatus(); this.createTable(); this.createForm(); this.createSearch(); this.grid.setVgap(5); this.grid.setHgap(5); this.grid.setAlignment(Pos.CENTER); var scene = new Scene(this.grid, 500, 400); stage.setScene(scene); stage.setTitle("Noten von Schülern"); stage.show(); } private void createStatus() { this.status = new Text(); this.grid.add(this.status, 0, 0, 2, 1); } private void createSearch() { var field = new TextField(); var button = new Button("Suchen"); var line = new Separator(); var table = new TableView(); try { var handler = new SearchAction(this.connection, this.status, field); table.setItems(handler.getMarks()); var subjectColumn = new TableColumn("Fach"); subjectColumn.setCellValueFactory( new PropertyValueFactory<>("subject" /* handler.getMarks().get(0).subjectProperty().getName() */) ); var markColumn = new TableColumn("Note"); markColumn.setCellValueFactory( new PropertyValueFactory<>("mark" /* handler.getMarks().get(0).markProperty().getName() */) ); table.getColumns().setAll(subjectColumn, markColumn); button.setOnAction(handler); } catch (SQLException exception) { this.status.setText(exception.getMessage()); } line.setMinSize(10, 10); this.grid.add(line, 0, 6, 2, 1); this.grid.add(button, 0, 7); this.grid.add(field, 1, 7); this.grid.add(table, 0, 8, 2, 1); } private void createForm() { var nameField = new TextField(); var nameLabel = new Label("Name"); var englishField = new TextField(); var englishLabel = new Label("Englisch"); var germanField = new TextField(); var germanLabel = new Label("Deutsch"); var mathField = new TextField(); var mathLabel = new Label("Mathematik"); var saveButton = new Button("Speichern"); try { var action = new SaveAction(this.connection, nameField, englishField, germanField, mathField, this.status); saveButton.setOnAction(action); } catch (SQLException exception) { this.status.setText(exception.getMessage()); } this.grid.add(nameLabel, 0, 1); this.grid.add(nameField, 1, 1); this.grid.add(englishLabel, 0, 2); this.grid.add(englishField, 1, 2); this.grid.add(germanLabel, 0, 3); this.grid.add(germanField, 1, 3); this.grid.add(mathLabel, 0, 4); this.grid.add(mathField, 1, 4); this.grid.add(saveButton, 1, 5); } private void createTable() { try { var host = "jdbc:hsqldb:mem:mitarbeiter;shutdown=true"; this.connection = DriverManager.getConnection(host); var statement = connection.createStatement(); statement.executeUpdate(""" CREATE TABLE IF NOT EXISTS marks ( mark_id identity PRIMARY KEY, name VARCHAR, english integer, german integer, math integer ) """); } catch (SQLException exception) { this.status.setText(exception.getMessage()); } } }