Guest User

jfxcode1

a guest
Aug 17th, 2023
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | Software | 0 0
  1. /*
  2.  *ex1
  3.  */
  4. package tereadsblog_javafx;
  5.  
  6. import javafx.application.Application;
  7. import javafx.application.Platform;
  8.  
  9. import javafx.scene.Group;
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.Label;
  12. import javafx.scene.layout.VBox;
  13. import javafx.scene.paint.Color;
  14. import javafx.stage.Stage;
  15.  
  16. /**
  17.  *
  18.  * @author admin
  19.  */
  20. public class TereadsBlog_JavaFX extends Application {
  21.  
  22.     Stage stage = new Stage();
  23.     Group gp = new Group();
  24.     Scene scene = new Scene(gp, 400, 400, Color.ALICEBLUE);
  25.  
  26.     Label labelThread1 = new Label("Resultado Trhead 1:");
  27.     Label labelThread2 = new Label("Resultado Trhead 2:");
  28.     VBox vb1 = new VBox();
  29.  
  30.     Thread threadOne;
  31.     Thread threadTWO;
  32.  
  33.     String str_X = "Citroen";
  34.     String str_Y = "Pegeot";
  35.     String strRNome;
  36.  
  37.     int int_X = 1; // citroen
  38.     int int_Y = 3; //pegeot
  39.     int intR_Carros;
  40.      int int_DIF_R_Carros;
  41.     @Override
  42.     public void start(Stage primaryStage) {
  43.  
  44.         stage.setScene(scene);
  45.         vb1.getChildren().addAll(labelThread1, labelThread2);
  46.         gp.getChildren().addAll(vb1); //nodes para um vb
  47.  
  48.         //trheads 1
  49.         ArranqueOne();
  50.         //trheads 2
  51.         ArranqueTWO();
  52.  
  53.         stage.show();
  54.  
  55.     }
  56.  
  57.     public static void main(String[] args) {
  58.         launch(args);
  59.     }
  60.  
  61.     private void ArranqueOne() {
  62.         //expreΓ§ao Lambda
  63.         threadOne = new Thread(() -> {
  64.  
  65.             if (int_X > int_Y) {
  66.                 intR_Carros = int_X;
  67.                 strRNome = str_X;
  68.             } else {
  69.                 intR_Carros = int_Y;
  70.                 strRNome = str_Y;
  71.  
  72.             }
  73.             Platform.runLater(() ->
  74.                     labelThread1.setText(""
  75.                             + "A maior quantidade de frota de carros Γ© de "
  76.                             + "" + strRNome + " quantidade " + intR_Carros));
  77.  
  78.         });
  79.         threadOne.start();
  80.     }
  81.  
  82.     private void ArranqueTWO() {
  83.         threadTWO = new Thread(() -> {
  84.  
  85.             int_DIF_R_Carros = (int ) int_X - (int) int_Y;
  86.             Platform.runLater(() -> labelThread2.setText("A  a diferencia na frota Γ© de"
  87.                   + int_DIF_R_Carros));
  88.  
  89.         });
  90.  
  91.         threadTWO.start();
  92.     }
  93.  
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment