Cannot set javafx.scene.control.TextField to field ‘texField‘

本文讨论了一个常见的编程错误,即在使用JavaFX时错误地导入了`java.awt`包而不是正确的`javafx.scene.control`包。解释了这个错误的原因,并提供了正确的导入方式,帮助开发者解决此类问题。
摘要由CSDN通过智能技术生成

类似这种错误,大概率是因为Controller导错包了
Javafx的包为javafx.scene.control,而不是java.awt

package application; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class ACSDHomework3III extends Application { TextField tfA = new TextField(); TextField tfB = new TextField(); TextField tfC = new TextField(); TextField tfD = new TextField(); Button btisDight = new Button(" is Dight "); Button btisNum = new Button(" is Num "); Button bttoUp = new Button(" to Up "); Button bttoLow = new Button(" to Low "); Button btisUp = new Button(" is Up "); @Override public void start(Stage primaryStage) { GridPane gridPane = new GridPane(); gridPane.setHgap(5); gridPane.setVgap(5); gridPane.add(new Label("Class ID:"), 0, 0); gridPane.add(tfA, 1, 0); gridPane.add(new Label("Name:"), 0, 1); gridPane.add(tfB, 1, 1); gridPane.add(new Label("A Character"), 1, 2); gridPane.add(new Label("Result"), 5, 3); gridPane.add(tfC, 1, 4); gridPane.add(tfD, 5, 4); gridPane.setAlignment(Pos.CENTER); tfD.setAlignment(Pos.BOTTOM_RIGHT); HBox hBox = new HBox(btisDight,btisNum,bttoUp,bttoLow,btisUp); hBox.getChildren().addAll(); hBox.setAlignment(Pos.CENTER); BorderPane borderPane = new BorderPane(); borderPane.setCenter(gridPane); borderPane.setBottom(hBox); btisDight.setOnAction(e -> isDight()); btisNum.setOnAction(e -> isNum()); bttoUp.setOnAction(e -> toUp()); bttoLow.setOnAction(e -> toLow()); btisUp.setOnAction(e -> isUp()); Scene scene = new Scene(borderPane, 500, 200); primaryStage.setTitle("William 201045"); primaryStage.setScene(scene); primaryStage.show(); } String C; private void isDight() { tfD = Charater.isDight(tfC.setText); } private void isNum() { tfC.setText((String.format("%.2f",Charater.isNum(C)))); } private void toUp() { tfC.setText((String.format("%.2f",Charater.toUpCase(C)))); } private void toLow() { tfC.setText((String.format("%.2f",Charater.toLowCase(C)))); } private void isUp() { tfC.setText((String.format("%.2f",Charater.isUpCase(C)))); } public static void main(String[] args) { launch(args); } }怎么修改错误的地方
06-07
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值