Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. package application;
  2.  
  3. import java.util.Timer;
  4. import java.util.TimerTask;
  5.  
  6. import javafx.application.Application;
  7. import javafx.scene.Group;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.control.Label;
  11. import javafx.scene.layout.Pane;
  12. import javafx.stage.Stage;
  13.  
  14. public class Main extends Application {
  15.  
  16. public float clic ;
  17. public float time = 10000;
  18. public float result ;
  19. @Override
  20. public void start(Stage primaryStage) {
  21. try {
  22. Group root = new Group();
  23. Scene scene = new Scene(root,225,150);
  24.  
  25. Label la = new Label(" Clic pour commencer le test !");
  26.  
  27. root.setAutoSizeChildren(true);
  28.  
  29.  
  30. Button bu = new Button("Clic");
  31. bu.setLayoutX(91);
  32. bu.setLayoutY(50);
  33. bu.setOnAction(event ->{
  34. clic = clic + 1;
  35.  
  36.  
  37. Label lab = new Label("Clic : " + clic);
  38. lab.setLayoutX(86);
  39. lab.setLayoutY(30);
  40.  
  41.  
  42. try {
  43. Thread.sleep(20);
  44. root.getChildren().add(lab);
  45. Thread.sleep(20);
  46. root.getChildren().remove(lab);
  47. } catch (InterruptedException e) {
  48. // TODO Auto-generated catch block
  49. e.printStackTrace();
  50. }
  51.  
  52.  
  53.  
  54.  
  55. System.out.println(clic);
  56. Timer timer = new Timer();
  57. timer.schedule(new TimerTask() {
  58.  
  59. @Override
  60. public void run() {
  61.  
  62. result = clic / 10 ;
  63. System.out.println("Ton CPS est de : " + result + ".");
  64. Label res = new Label(" Ton \"" + "CPS" + "\" est de : " + result );
  65. res.setLayoutY(100);
  66.  
  67.  
  68. root.getChildren().addAll(res);
  69. }
  70. }, 10000);
  71.  
  72.  
  73. });
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. Button removeButton = new Button("Recomencer le test !");
  81. removeButton.setLayoutY(135);
  82. removeButton.setOnAction(event -> {
  83. System.out.println("---{ }---");
  84. System.out.println( clic + "| |" +result + "\n");
  85. clic = 0; result = 0;
  86. System.out.println(clic + "| |" +result);
  87. });
  88.  
  89. Pane pane = new Pane();
  90. pane.getStyleClass().add("bg-black-style");
  91.  
  92. root.getChildren().addAll(bu, la, removeButton, pane);
  93.  
  94.  
  95.  
  96.  
  97. primaryStage.setResizable(false);
  98. primaryStage.setTitle("TestCPS");
  99. primaryStage.setScene(scene);
  100. primaryStage.show();
  101. } catch(Exception e) {
  102. e.printStackTrace();
  103. }
  104. }
  105.  
  106. public static void main(String[] args) {
  107. launch(args);
  108. System.out.println("L'aplication vient de s'éiteindre !");
  109. System.exit(0);
  110. }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement