Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *ex1
- */
- package tereadsblog_javafx;
- import javafx.application.Application;
- import javafx.application.Platform;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.Label;
- import javafx.scene.layout.VBox;
- import javafx.scene.paint.Color;
- import javafx.stage.Stage;
- /**
- *
- * @author admin
- */
- public class TereadsBlog_JavaFX extends Application {
- Stage stage = new Stage();
- Group gp = new Group();
- Scene scene = new Scene(gp, 400, 400, Color.ALICEBLUE);
- Label labelThread1 = new Label("Resultado Trhead 1:");
- Label labelThread2 = new Label("Resultado Trhead 2:");
- VBox vb1 = new VBox();
- Thread threadOne;
- Thread threadTWO;
- String str_X = "Citroen";
- String str_Y = "Pegeot";
- String strRNome;
- int int_X = 1; // citroen
- int int_Y = 3; //pegeot
- int intR_Carros;
- int int_DIF_R_Carros;
- @Override
- public void start(Stage primaryStage) {
- stage.setScene(scene);
- vb1.getChildren().addAll(labelThread1, labelThread2);
- gp.getChildren().addAll(vb1); //nodes para um vb
- //trheads 1
- ArranqueOne();
- //trheads 2
- ArranqueTWO();
- stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- private void ArranqueOne() {
- //expreΓ§ao Lambda
- threadOne = new Thread(() -> {
- if (int_X > int_Y) {
- intR_Carros = int_X;
- strRNome = str_X;
- } else {
- intR_Carros = int_Y;
- strRNome = str_Y;
- }
- Platform.runLater(() ->
- labelThread1.setText(""
- + "A maior quantidade de frota de carros Γ© de "
- + "" + strRNome + " quantidade " + intR_Carros));
- });
- threadOne.start();
- }
- private void ArranqueTWO() {
- threadTWO = new Thread(() -> {
- int_DIF_R_Carros = (int ) int_X - (int) int_Y;
- Platform.runLater(() -> labelThread2.setText("A a diferencia na frota Γ© de"
- + int_DIF_R_Carros));
- });
- threadTWO.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment