// SPDX-FileCopyrightText: 2025 Jonas Smedegaard // SPDX-License-Identifier: GPL-3.0-or-later package dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.view; import java.util.List; import javafx.application.Application; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.Scene; import javafx.stage.Stage; import dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.Control; import dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.model.GUI; /// Bachelorizer - JavaFX Window view // Class is final to forbid subclassing, // because object is passed to controller during instatiation public final class Window extends Application { // the View /// Default constructor // (declared explicitly only to silence javadoc) public Window() { } /// Label styling public static String LABEL_STYLE = "-fx-font-weight: bold; -fx-font-size: 20;"; /// Application model private GUI model = new GUI(); /// Application controller private Control control = new Control(model, this); /// Name of student private TextField nameEntry = new TextField(); /// Text entry for adding an activity private TextField activityEntry = new TextField(); /// Text area for activity entries private TextArea area = new TextArea(); /// Button to delete one activity private Button delOne = new Button("Delete one"); /// Button to delete all activities private Button delAll = new Button("Delete all"); /// Application instantiation /// /// @param args application parameters public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { // pass application parameters to controller control.setParameters(getParameters().getRaw()); // add listeners // NameEntry.setOnAction(e -> control.enterName( // activityEntry.getText())); activityEntry.setOnAction(e -> control.enterActivity( activityEntry.getText())); delOne.setOnAction(e -> control.delOne()); delAll.setOnAction(e -> control.delAll()); // add buttons VBox root = new VBox(10, ourHBox("Student", nameEntry), ourHBox("Add activity", activityEntry), new HBox(10, delOne, delAll), area); // compose stage Scene scene = new Scene(root, 500, 500); stage.setTitle("JavaFX Demo"); stage.setScene(scene); stage.show(); } /// action to apply student name /// /// @param s Text to apply public void setStudentName(String s) { nameEntry.setText(s); } /// action to apply text to area /// /// @param s Text to apply public void setArea(String s) { area.setText(s); } /// Button action to clear field public void clearActivityEntry() { activityEntry.setText(""); } /// Styled HBox with label and TextField /// /// @param s Label string /// @param f Text field /// @return HBox containing styled label and text field public HBox ourHBox(String s, TextField f) { Label label = new Label(s+":"); label.setStyle(LABEL_STYLE); return new HBox(10, label, f); } }