A sentimental robot

Platform.runLater( ) 본문

Java

Platform.runLater( )

GOD03219 2018. 2. 7. 15:32

package Pack01;

import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

 

public class Hello extends Application {

 @Override
 public void start(Stage arg0) throws Exception {

  VBox vbox = new VBox();
  vbox.setPrefSize(300, 300);

 

  Button btn1 = new Button("Button");
  btn1.setOnAction(new EventHandler<>() {

   @Override
   public void handle(ActionEvent arg0) {
   
    new Thread() {
     @Override
     public void run() {

      Platform.runLater(() -> {
       btn1.setText("앵무새");

      });

     }

    }.start();

   }
  });
  vbox.getChildren().addAll(btn1);

 

  Scene scene = new Scene(vbox);
  arg0.setScene(scene);
  arg0.setTitle("server");
  arg0.show();

 }

 public static void main(String[] args) {

  launch();

 }

}

// Thread로 UI 만질 때 error발생 하면 Platform.runLater 함수 쓰기

'Java' 카테고리의 다른 글

1:1 채팅  (0) 2018.09.06
NullPointerException  (0) 2018.06.30
Chatting UI  (0) 2018.02.07
UI  (0) 2018.02.07
진수에 대해서  (0) 2018.01.09