Skip to content
Snippets Groups Projects
Commit 184c51a2 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

added pause button

parent 3c49ddb0
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,8 @@ import static java.lang.Thread.sleep; ...@@ -14,6 +14,8 @@ import static java.lang.Thread.sleep;
public class App extends Application { public class App extends Application {
boolean isInPause = true;
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
} }
...@@ -22,6 +24,7 @@ public class App extends Application { ...@@ -22,6 +24,7 @@ public class App extends Application {
public void start(Stage primaryStage) throws InterruptedException { public void start(Stage primaryStage) throws InterruptedException {
Group root = new Group(); Group root = new Group();
Button restart = new Button("Restart"); Button restart = new Button("Restart");
Button switchPause = new Button("Pause");
VBox buttons = new VBox(); VBox buttons = new VBox();
HBox total = new HBox(); HBox total = new HBox();
Grid grid = new Grid(1000,1000,20,20); Grid grid = new Grid(1000,1000,20,20);
...@@ -30,7 +33,9 @@ public class App extends Application { ...@@ -30,7 +33,9 @@ public class App extends Application {
total.getChildren().add(buttons); total.getChildren().add(buttons);
total.getChildren().add(grid); total.getChildren().add(grid);
buttons.getChildren().add(restart); buttons.getChildren().add(restart);
buttons.getChildren().add(switchPause);
restart.setOnMouseClicked(grid::restart); restart.setOnMouseClicked(grid::restart);
switchPause.setOnMouseClicked((value)->isInPause = !isInPause);
primaryStage.setScene(new Scene(root)); primaryStage.setScene(new Scene(root));
primaryStage.show(); primaryStage.show();
grid.repaint(); grid.repaint();
...@@ -39,9 +44,11 @@ public class App extends Application { ...@@ -39,9 +44,11 @@ public class App extends Application {
threadPoolExecutor.scheduleWithFixedDelay(new Runnable() { threadPoolExecutor.scheduleWithFixedDelay(new Runnable() {
@Override @Override
public void run() { public void run() {
if(!isInPause) {
grid.model.activation(); grid.model.activation();
grid.repaint(); grid.repaint();
} }
}
}, 0, 50 , TimeUnit.MILLISECONDS); }, 0, 50 , TimeUnit.MILLISECONDS);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment