我正在尝试创建一个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