a simple Java-FX Application which Simulate the Approximation of Pi https://nextn.xyz
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

  1. package montecarlopi;
  2. import java.util.concurrent.TimeUnit;
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5. import javafx.application.Platform;
  6. import javafx.scene.control.ListView;
  7. /**
  8. *
  9. * @author tobia
  10. */
  11. public class UpdateThread extends Thread {
  12. private int i = 0;
  13. private Model test;
  14. public UpdateThread(Model test, ListView<String> list, int count) {
  15. setDaemon(true);
  16. setName("Thread " + count);
  17. this.test = test;
  18. list.getItems().add(getName());
  19. }
  20. @Override
  21. public void run() {
  22. while (!this.isInterrupted()) {
  23. if (test.isExit()) {
  24. return;
  25. }
  26. Platform.runLater(new Runnable() {
  27. @Override
  28. public void run() {
  29. test.generatePoint();
  30. }
  31. });
  32. try {
  33. sleep(TimeUnit.MILLISECONDS.toMillis(5));
  34. } catch (InterruptedException ex) {
  35. Logger.getLogger(UpdateThread.class.getName()).log(Level.SEVERE, null, ex);
  36. }
  37. }
  38. }
  39. }