This commit is contained in:
2025-05-10 08:34:14 +02:00
parent 0ebb73d035
commit fdb6d64429
2 changed files with 4 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ import static UE20_290425_Threads2.Pferderennen.textArea;
public class Horse extends ProgressBar implements Runnable {
private static final double finish_line = 1_000_000;
private static final double maxSleepTime = 100, maxStepSize = 10_000;
private static final double maxSleepTime = 1, maxStepSize = 10_000;
private final int index;
private double pos = 0;
@@ -16,10 +16,6 @@ public class Horse extends ProgressBar implements Runnable {
this.index = index;
}
public double getPos() {
return this.pos;
}
public void setPos(double pos) {
this.pos = pos;
}

View File

@@ -18,13 +18,14 @@ public class Pferderennen extends Application {
protected static final TextArea textArea = new TextArea();
protected static final ArrayList<Horse> horses = new ArrayList<>();
private static final ArrayList<Thread> threads = new ArrayList<>();
private static boolean lock = false, reset = false;
private static boolean lock = false;
public static void main(String[] args) {
launch(args);
}
private static void startRace() {
for (Horse horse : horses) horse.setPos(0);
threads.clear();
for (Horse horse : horses) {
Thread thread = new Thread(horse);
@@ -49,24 +50,18 @@ public class Pferderennen extends Application {
BorderPane backPane = new BorderPane();
Label titel = new Label("Pferderennen - mit Threads");
// titel.setStyle("-fx-font-size: 16px;");
backPane.setTop(titel);
// BorderPane.setAlignment(titel, CENTER);
VBox button_box = new VBox(10);
// button_box.setPadding(new Insets(10));
Button button_plus = new Button("+");
Button button_minus = new Button("-");
button_box.getChildren().addAll(button_plus, button_minus);
backPane.setLeft(button_box);
// Rechts: Start-Button
Button button_start = new Button("Start");
VBox start_box = new VBox(button_start);
start_box.setPadding(new Insets(10));
// start_box.setSpacing(10);
backPane.setRight(start_box);
// VBox.setMargin(button_start, new Insets(5));
textArea.setPrefRowCount(10);
textArea.setEditable(false);
@@ -98,13 +93,11 @@ public class Pferderennen extends Application {
textArea.appendText("Please wait for the race to finish\n");
return;
}
for (Horse horse : horses) horse.setProgress(0);
lock = true;
textArea.appendText("Ergebnis:\n");
startRace();
});
// Scene und Stage
Scene scene = new Scene(backPane, 600, 400);
stage.setTitle("Pferderennen");
stage.setScene(scene);