我想为faculty类(facultyapp的子类)创建一个对象,在这里我可以输入一些值
错误:不兼容的类型:字符串不能转换为textfield faculty=new faculty(“,”“,”“);
FXMLDocumentController
公共类fxmldocumentcontroller实现可初始化{
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
公共类教员扩展facultyapp{私有文本字段标题、姓名、地址;
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;
}
}
1条答案
按热度按时间tez616oj1#
你的
Faculty
类的构造函数需要3个类型为TextField
,但你想通过3级String
物体。既然您使用的是setter,为什么不删除当前的构造函数并创建一个新的
Faculty
通过使用默认构造函数?所以把这个从
Faculty
班级:而且在
FXMLDocumentController
改变进入之内