所以我似乎找不到关于为什么Eclipse无法识别“ setPromptText”功能的任何信息。它在问我是否要创建方法setPromptText:
import javafx.application.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.event.*;
import javafx.geometry.*;
public class TextField extends Application {
TextField tf;
Label response;
public static void main(String [] args) {
launch(args);
}
public void start(Stage myStage) {
myStage.setTitle("Demonstrate a textfield");
FlowPane rootNode = new FlowPane(10,10);
rootNode.setAlignment(Pos.CENTER);
Scene myScene = new Scene(rootNode, 230, 140);
myStage.setScene(myScene);
response = new Label("Enter Name: ");
Button btnGetText = new Button("Get Name");
tf = new TextField();
tf.setPromptText("Enter a name.");
}
}
答案 0 :(得分:1)
您需要更改班级的名称,
或者您可以在new Textfield()
声明中指定软件包。
E.G将相关行更改为此:
tf = new javafx.scene.control.TextField();
答案 1 :(得分:1)
这是因为您的类名也是TextField。
import javafx.application.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.event.*;
import javafx.geometry.*;
public class TextField extends Application {
javafx.scene.control.TextField tf;
Label response;
public static void main(String [] args) {
launch(args);
}
public void start(Stage myStage) {
myStage.setTitle("Demonstrate a textfield");
FlowPane rootNode = new FlowPane(10,10);
rootNode.setAlignment(Pos.CENTER);
Scene myScene = new Scene(rootNode, 230, 140);
myStage.setScene(myScene);
response = new Label("Enter Name: ");
Button btnGetText = new Button("Get Name");
tf = new javafx.scene.control.TextField();
tf.setPromptText("Enter a name.");
}
}
此代码有效