Search in sources :

Example 6 with Tests

use of eu.tn.model.Tests in project TNCY-English-Project by mrngg.

the class DbTestsController method editTest.

@FXML
public void editTest() throws IOException {
    if (testsListView.getSelectionModel().getSelectedItem() != null) {
        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(25, 25, 25, 25));
        Label name = new Label("Name :");
        TextField nameTF = new TextField();
        nameTF.setText(testsListView.getSelectionModel().getSelectedItem().toString());
        grid.add(nameTF, 1, 1);
        grid.add(name, 0, 1);
        Button btn = new Button("Edit");
        grid.add(btn, 0, 3);
        Scene secondScene = new Scene(grid, 300, 150);
        Stage newWindow = new Stage();
        newWindow.setTitle("Edit a test");
        newWindow.setScene(secondScene);
        newWindow.show();
        btn.setOnAction((event) -> {
            if (nameTF.getText() != null) {
                for (Tests t : tests) {
                    if (t.getName().equals(testsListView.getSelectionModel().getSelectedItem().toString())) {
                        t.setName(nameTF.getText());
                    }
                }
                ObservableList<String> items = FXCollections.observableArrayList();
                for (int i = 0; i < tests.size(); i++) {
                    items.add(tests.get(i).getName());
                }
                testsListView.setItems(items);
                newWindow.close();
                try {
                    new Database().save();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Label(javafx.scene.control.Label) IOException(java.io.IOException) Scene(javafx.scene.Scene) Tests(eu.tn.model.Tests) Button(javafx.scene.control.Button) Database(eu.tn.model.Database) TextField(javafx.scene.control.TextField) Stage(javafx.stage.Stage) FXML(javafx.fxml.FXML)

Example 7 with Tests

use of eu.tn.model.Tests in project TNCY-English-Project by mrngg.

the class TestsChoiceController method startTest.

public void startTest() throws IOException {
    if (testschoicebox.getValue() != null) {
        Stage primaryStage = new Stage();
        primaryStage.setTitle("Shakespeare");
        BorderPane root = new BorderPane();
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(getClass().getResource("../view/AnswerSheet.fxml"));
        for (Tests t : tests) {
            if (t.getName().equals(testschoicebox.getValue())) {
                loader.setControllerFactory((iC -> new AnswerSheetController(t)));
            }
        }
        root.setCenter(loader.load());
        primaryStage.setOnCloseRequest(event -> {
            Platform.exit();
        });
        primaryStage.setTitle("Shakespeare");
        primaryStage.setScene(new Scene(root, 820, 490));
        primaryStage.show();
        Stage stage = (Stage) testschoicebox.getScene().getWindow();
        stage.close();
    }
}
Also used : Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Scene(javafx.scene.Scene) Stage(javafx.stage.Stage) FXMLLoader(javafx.fxml.FXMLLoader) Tests.tests(eu.tn.model.Tests.tests) IOException(java.io.IOException) Tests(eu.tn.model.Tests) BorderPane(javafx.scene.layout.BorderPane) ChoiceBox(javafx.scene.control.ChoiceBox) BorderPane(javafx.scene.layout.BorderPane) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) Tests(eu.tn.model.Tests)

Aggregations

Tests (eu.tn.model.Tests)7 Database (eu.tn.model.Database)5 IOException (java.io.IOException)4 FXML (javafx.fxml.FXML)4 Scene (javafx.scene.Scene)3 Stage (javafx.stage.Stage)3 Rules (eu.tn.model.Rules)2 Insets (javafx.geometry.Insets)2 Button (javafx.scene.control.Button)2 Label (javafx.scene.control.Label)2 TextField (javafx.scene.control.TextField)2 GridPane (javafx.scene.layout.GridPane)2 Tests.tests (eu.tn.model.Tests.tests)1 Platform (javafx.application.Platform)1 FXMLLoader (javafx.fxml.FXMLLoader)1 ChoiceBox (javafx.scene.control.ChoiceBox)1 BorderPane (javafx.scene.layout.BorderPane)1