【发布时间】:2016-11-24 18:55:30
【问题描述】:
我正在尝试创建一个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();
}
}
我想获取在“Hello”窗口中输入的名称,以便在另一个类中使用它ShowOff。
炫耀类
import javafx.application.Application;
public class ShowOff {
ShowOff() {
Application.launch(start.class,"myClass");
}
public static void main(String[] args)
{
}
}
我该如何实现呢?
【问题讨论】:
-
你想要什么值得到“hello”窗口?
-
我想要窗口中的名字字符串
-
您可以轻松地将字符串从
ShowOff()传递到start(),但反之亦然会有点笨拙。我并不是说这是不可能的,但 IMO,这不是正确的方法。 -
好的,我该怎么做呢?我是新来的,如果你能给我一个合适的例子,那就太好了。两种方式都会好很多
标签: java inheritance javafx