UE20
This commit is contained in:
@@ -7,7 +7,7 @@ import static UE20_290425_Threads2.Pferderennen.textArea;
|
|||||||
|
|
||||||
public class Horse extends ProgressBar implements Runnable {
|
public class Horse extends ProgressBar implements Runnable {
|
||||||
private static final double finish_line = 1_000_000;
|
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 final int index;
|
||||||
private double pos = 0;
|
private double pos = 0;
|
||||||
|
|
||||||
@@ -16,10 +16,6 @@ public class Horse extends ProgressBar implements Runnable {
|
|||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPos() {
|
|
||||||
return this.pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPos(double pos) {
|
public void setPos(double pos) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,14 @@ public class Pferderennen extends Application {
|
|||||||
protected static final TextArea textArea = new TextArea();
|
protected static final TextArea textArea = new TextArea();
|
||||||
protected static final ArrayList<Horse> horses = new ArrayList<>();
|
protected static final ArrayList<Horse> horses = new ArrayList<>();
|
||||||
private static final ArrayList<Thread> threads = 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) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startRace() {
|
private static void startRace() {
|
||||||
|
for (Horse horse : horses) horse.setPos(0);
|
||||||
threads.clear();
|
threads.clear();
|
||||||
for (Horse horse : horses) {
|
for (Horse horse : horses) {
|
||||||
Thread thread = new Thread(horse);
|
Thread thread = new Thread(horse);
|
||||||
@@ -49,24 +50,18 @@ public class Pferderennen extends Application {
|
|||||||
BorderPane backPane = new BorderPane();
|
BorderPane backPane = new BorderPane();
|
||||||
|
|
||||||
Label titel = new Label("Pferderennen - mit Threads");
|
Label titel = new Label("Pferderennen - mit Threads");
|
||||||
// titel.setStyle("-fx-font-size: 16px;");
|
|
||||||
backPane.setTop(titel);
|
backPane.setTop(titel);
|
||||||
// BorderPane.setAlignment(titel, CENTER);
|
|
||||||
|
|
||||||
VBox button_box = new VBox(10);
|
VBox button_box = new VBox(10);
|
||||||
// button_box.setPadding(new Insets(10));
|
|
||||||
Button button_plus = new Button("+");
|
Button button_plus = new Button("+");
|
||||||
Button button_minus = new Button("-");
|
Button button_minus = new Button("-");
|
||||||
button_box.getChildren().addAll(button_plus, button_minus);
|
button_box.getChildren().addAll(button_plus, button_minus);
|
||||||
backPane.setLeft(button_box);
|
backPane.setLeft(button_box);
|
||||||
|
|
||||||
// Rechts: Start-Button
|
|
||||||
Button button_start = new Button("Start");
|
Button button_start = new Button("Start");
|
||||||
VBox start_box = new VBox(button_start);
|
VBox start_box = new VBox(button_start);
|
||||||
start_box.setPadding(new Insets(10));
|
start_box.setPadding(new Insets(10));
|
||||||
// start_box.setSpacing(10);
|
|
||||||
backPane.setRight(start_box);
|
backPane.setRight(start_box);
|
||||||
// VBox.setMargin(button_start, new Insets(5));
|
|
||||||
|
|
||||||
textArea.setPrefRowCount(10);
|
textArea.setPrefRowCount(10);
|
||||||
textArea.setEditable(false);
|
textArea.setEditable(false);
|
||||||
@@ -98,13 +93,11 @@ public class Pferderennen extends Application {
|
|||||||
textArea.appendText("Please wait for the race to finish\n");
|
textArea.appendText("Please wait for the race to finish\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Horse horse : horses) horse.setProgress(0);
|
|
||||||
lock = true;
|
lock = true;
|
||||||
textArea.appendText("Ergebnis:\n");
|
textArea.appendText("Ergebnis:\n");
|
||||||
startRace();
|
startRace();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Scene und Stage
|
|
||||||
Scene scene = new Scene(backPane, 600, 400);
|
Scene scene = new Scene(backPane, 600, 400);
|
||||||
stage.setTitle("Pferderennen");
|
stage.setTitle("Pferderennen");
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
|
|||||||
Reference in New Issue
Block a user