我正在嘗試創建一個TextField
以獲取用戶名。我創建了一個包含UI組件的新類。如何獲取課程價值並將其傳遞給另一個課程?
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class start extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Label label = new Label("Name:");
TextField textField = new TextField();
HBox hBox = new HBox();
hBox.getChildren().addAll(label,textField);
hBox.setSpacing(10);
Scene scene = new Scene(hBox,300,200);
primaryStage.setScene(scene);
primaryStage.setTitle("Hello");
primaryStage.show();
}
}
我想在「你好」窗口中輸入的名稱在其他類ShowOff
使用它。
ShowOff類
import javafx.application.Application;
public class ShowOff {
ShowOff() {
Application.launch(start.class,"myClass");
}
public static void main(String[] args)
{
}
}
我怎麼能實現呢?
你想要什麼樣的價值得到「你好」窗口? – ItachiUchiha
我想要窗口中的名稱字符串 – IAmBlake
您可以很容易地將'ShowOff()'中的字符串傳遞給'start()',但反過來會有點笨拙。我不是說這不可能,但是海事組織,這不是正確的做法。 – ItachiUchiha