UE20
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package UE19_220425_Threads.nothread;
|
||||
package UE19_220425_Threads1.nothread;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package UE19_220425_Threads.reallyParallel;
|
||||
package UE19_220425_Threads1.reallyParallel;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package UE19_220425_Threads.runnable;
|
||||
package UE19_220425_Threads1.runnable;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package UE19_220425_Threads.thread;
|
||||
package UE19_220425_Threads1.thread;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package UE19_220425_Threads.thread_right;
|
||||
package UE19_220425_Threads1.thread_right;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
119
src/UE20_290425_Threads2/Pferderennen.java
Normal file
119
src/UE20_290425_Threads2/Pferderennen.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package UE20_290425_Threads2;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Pferderennen extends Application {
|
||||
private static final ArrayList<ProgressBar> bars = new ArrayList<>();
|
||||
private static final int maxSleepTime = 10;
|
||||
private static final int maxStepSize = 10;
|
||||
private static final List<Double> horses = new ArrayList<>();
|
||||
private static boolean lock = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
private static void startRace() {
|
||||
// ArrayList<Thread>
|
||||
}
|
||||
|
||||
private static void endRace() {
|
||||
lock = false;
|
||||
}
|
||||
|
||||
public static int random(int max) {
|
||||
return (int) (Math.random() * max + 1);
|
||||
}
|
||||
|
||||
private synchronized void addToHorse(int horseIndex) {
|
||||
int step = random(maxStepSize);
|
||||
int sleep = random(maxSleepTime);
|
||||
horses.set(horseIndex, horses.get(horseIndex) + step);
|
||||
try {
|
||||
Thread.sleep(sleep);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
BorderPane backPane = new BorderPane();
|
||||
|
||||
Label titel = new Label("Pferderennen - mit Threads");
|
||||
// titel.setStyle("-fx-font-size: 16px;");
|
||||
backPane.setTop(titel);
|
||||
// BorderPane.setAlignment(titel, CENTER);
|
||||
|
||||
// Links: VBox mit zwei Buttons (+ / -)
|
||||
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 textArea = new TextArea();
|
||||
textArea.setPrefRowCount(10);
|
||||
textArea.setEditable(false);
|
||||
backPane.setBottom(textArea);
|
||||
|
||||
VBox horse_bars = new VBox(10);
|
||||
|
||||
for (ProgressBar bar : bars) horse_bars.getChildren().add(bar);
|
||||
|
||||
backPane.setCenter(horse_bars);
|
||||
|
||||
button_plus.setOnAction(_ -> {
|
||||
if (lock) {
|
||||
textArea.appendText("Please wait for the race to finish\n");
|
||||
return;
|
||||
}
|
||||
ProgressBar bar = new ProgressBar(0);
|
||||
bar.setMaxWidth(Double.MAX_VALUE);
|
||||
bars.add(bar);
|
||||
horse_bars.getChildren().add(bar);
|
||||
textArea.appendText("Adding " + bars.size() + " Bars\n");
|
||||
});
|
||||
button_minus.setOnAction(_ -> {
|
||||
if (lock) {
|
||||
textArea.appendText("Please wait for the race to finish\n");
|
||||
return;
|
||||
}
|
||||
if (!bars.isEmpty()) {
|
||||
horse_bars.getChildren().remove(bars.removeLast());
|
||||
textArea.appendText("Adding " + bars.size() + " Bars\n");
|
||||
}
|
||||
});
|
||||
button_start.setOnAction(_ -> {
|
||||
lock = true;
|
||||
startRace();
|
||||
});
|
||||
|
||||
// Scene und Stage
|
||||
Scene scene = new Scene(backPane, 600, 400);
|
||||
stage.setTitle("Pferderennen");
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
}
|
||||
BIN
src/UE20_290425_Threads2/SEW3 UE20 2024 Pferderennen.pdf
Normal file
BIN
src/UE20_290425_Threads2/SEW3 UE20 2024 Pferderennen.pdf
Normal file
Binary file not shown.
5
src/UE20_290425_Threads2/horse.java
Normal file
5
src/UE20_290425_Threads2/horse.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package UE20_290425_Threads2;
|
||||
|
||||
public class horse {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user