2017-08-12 13 views
0

GUI用に個別のスレッドを作成するか、自動的に作成する必要がありますか?もし私がこれをどうすればいいの? GUIの実行方法がわかりません。GUI用に別のスレッド

package sample; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 

public class MyMain extends Application implements Runnable 
{ 
@Override 
public void run() 
{ 

} 

@Override 
public void start(Stage primaryStage) throws Exception 
{ 
    Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); 
    primaryStage.setTitle("Hello World"); 
    primaryStage.setScene(new Scene(root, 200, 300)); 
    primaryStage.setMinWidth(220); 
    primaryStage.setMinHeight(340); 
    primaryStage.show(); 
} 

public static void main(String[] args) { 
    launch(args); 
} 
} 

答えて

1

新しいスレッドを作成する必要はありません。ただ、このコードを使用します。

public class MyMain extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); 
     primaryStage.setTitle("Hello World"); 
     primaryStage.setScene(new Scene(root, 200, 300)); 
     primaryStage.setMinWidth(220); 
     primaryStage.setMinHeight(340); 
     primaryStage.show(); 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

Applicationクラスは、それ自体でスレッドの世話をします。

関連する問題