如何将 String 转换为 TextField,javaFX。来自 child class

How can I convert String into TextField, javaFX. from the child class

我想为 Faculty class(FacultyApp 的 child class)创建一个 object,我可以在其中输入一些值

错误:类型不兼容:无法将字符串转换为 TextField 学院 faculty = new Faculty(" ", " ", " ");

FXMLDocumentController

public class FXMLDocumentController 实现 Initializable {

private Label label;
@FXML
private TextField employeeName;
@FXML
private TextField employeeTitle;
@FXML
private TextField emailAddress;
@FXML
private Button SaveButton;




@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
}    
public void setNAME(TextField employeeName) {
     employeeName.getText();    
}
public void setADDRESS(TextField emailAddress) {
    emailAddress.getText();
}
public void setTITLE(TextField employeeTitle) {

employeeTitle.getText();
}

@FXML
private void saveInfo(ActionEvent event) {
    Faculty faculty = new Faculty(" ", " ", " ");
    String textField = new TextField().toString();
    faculty.setNAME(employeeName);
    faculty.setADDRESS(emailAddress);
    faculty.setTITLE(employeeTitle);
    
    String message = "YOUR INPUT HAS BEEN SAVED";
    Alert a = new Alert(AlertType.INFORMATION); 
    a.setContentText(message +"\nEmployee Name: "+employeeName +"\nEmployee Title: "+ employeeTitle +"\nEmail Address: " + emailAddress);
    a.show();  
    
}

}

childClass from MainClass

public class Faculty 扩展 FacultyApp{ private TextField 标题、姓名、地址;

public Faculty (TextField employeeName, TextField emailAddress, TextField employeeTitle){
    title = employeeTitle;
    name = employeeName;
    address = emailAddress;
}

public void setNAME(TextField employeeName) {
    name = employeeName;
}
public TextField  getNAME(){
    return name;
}
public void setADDRESS(TextField emailAddress) {
    address = emailAddress;
}
public TextField getADDRESS(){
    return address;
}

public void setTITLE(TextField employeeTitle) {
    title = employeeTitle;
}
public TextField getTITLE(){
    return title;
}

}

您的 Faculty Class' 构造函数需要 3 个 TextField 类型的参数,但您试图传递 3 个 String 对象。

既然你在使用 setter,为什么不删除当前构造函数并使用默认构造函数创建一个新的 Faculty 对象?

所以从 Faculty class 中删除这个:

public Faculty (TextField employeeName, TextField emailAddress, TextField employeeTitle){
    title = employeeTitle;
    name = employeeName;
    address = emailAddress;
}

并在FXMLDocumentController变化

Faculty faculty = new Faculty(" ", " ", " ");

进入

Faculty faculty = new Faculty();