Stop Button

This commit is contained in:
2024-05-06 16:42:25 +02:00
parent 0db7c7d840
commit fbc3ef0f70
3 changed files with 26 additions and 9 deletions

View File

@ -62,28 +62,39 @@ public class Controller_Frontend {
@FXML @FXML
private Label intconLabel; private Label intconLabel;
@FXML @FXML
private Button stepButton; private Button stepButton;
@FXML @FXML
private Button autoRunGUI; private Button autoRunGUI;
@FXML
private Button stopButton;
private volatile boolean isAutoRunActive = true;
@FXML
private void stopAutoRun(ActionEvent event) {
isAutoRunActive = false;
}
@FXML @FXML
private void autoRunGUI(ActionEvent event) { private void autoRunGUI(ActionEvent event) {
if (!isAutoRunActive) {
isAutoRunActive = true;
}
Thread autoRunThread = new Thread(() -> { Thread autoRunThread = new Thread(() -> {
try { try {
while (DataRegister.getPC() < prog.length) { while (DataRegister.getPC() < prog.length && isAutoRunActive){
Platform.runLater(() -> { Platform.runLater(() -> {
try { try {
@ -92,7 +103,7 @@ public class Controller_Frontend {
e.printStackTrace(); e.printStackTrace();
} }
}); });
Thread.sleep(200); // Millisekunden Thread.sleep(200); //Verzögerungszeit in Millisekunden
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
@ -100,9 +111,12 @@ public class Controller_Frontend {
}); });
autoRunThread.setDaemon(true); autoRunThread.setDaemon(true);
autoRunThread.start(); autoRunThread.start();
} }
@FXML @FXML
private void stepintoButton(ActionEvent event) throws IOException { private void stepintoButton(ActionEvent event) throws IOException {
if (lstContentListView.getItems().isEmpty()) { if (lstContentListView.getItems().isEmpty()) {
@ -295,6 +309,7 @@ public class Controller_Frontend {
lstContentListView.getStylesheets().add(Objects.requireNonNull(getClass().getResource("styles.css")).toExternalForm()); lstContentListView.getStylesheets().add(Objects.requireNonNull(getClass().getResource("styles.css")).toExternalForm());
autoRunGUI.setOnAction(this::autoRunGUI); autoRunGUI.setOnAction(this::autoRunGUI);
stopButton.setOnAction(this::stopAutoRun);
} }
private static void setTRISbuttons(ToggleButtonGroup[] allButtons) { private static void setTRISbuttons(ToggleButtonGroup[] allButtons) {

View File

@ -2,3 +2,4 @@
.list-cell:selected { .list-cell:selected {
-fx-background-color: yellow; -fx-background-color: yellow;
} }

View File

@ -28,6 +28,7 @@
<!--RIchtiger AUtorun button für die Gui der funktioniert --> <!--RIchtiger AUtorun button für die Gui der funktioniert -->
<Button fx:id="autoRunGUI" layoutX="182.0" layoutY="400.0" text="Auto Run" onAction="#autoRunGUI"/> <Button fx:id="autoRunGUI" layoutX="182.0" layoutY="400.0" text="Auto Run" onAction="#autoRunGUI"/>
<Button fx:id="stopButton" layoutX="302.0" layoutY="400.0" text="Stop" onAction="#stopAutoRun"/>
<HBox layoutX="807.0" layoutY="134.0" prefHeight="293.0" prefWidth="701.0"> <HBox layoutX="807.0" layoutY="134.0" prefHeight="293.0" prefWidth="701.0">
<children> <children>