我有一个带有其构造函数的Course类:
public class Course extends AbstractSubmission {
private String course_content;
public Course(String course_name, String username, String course_content) {
this.set_course_name(course_name);
this.set_username(username);
this.set_ip_address("null");
this.set_timestamp(new Date());
this.set_course_content(course_content);
}
public Course(Course course) {
this.set_course_id(course.get_course_id());
this.set_course_name(course.get_course_name());
this.set_username(course.get_username());
this.set_ip_address(course.get_ip_address());
this.set_timestamp(course.get_timestamp());
this.set_course_content(course.get_course_content());
}
我想基本上使用课程类来初始化javaFX tableview而不更改原始构造函数。我想使用表列作为参数的构造函数。我搜索了包装方法/类,但是我对如何做到这一点有些迷茫。请帮忙:)
public class AdminAllCoursesController implements Initializable {
@FXML private TableView<Course> coursesTable = new TableView<>();
@FXML private TableColumn<Course, Integer> id;
@FXML private TableColumn<Course, String> courseName;
@FXML private TableColumn<Course, String> courseIP;
@FXML private TableColumn<Course, Date> courseTimeStamp;
@FXML private TableColumn<Course, String> addedBy;
@FXML private TableColumn<Course, String> courseContent;
@Override
public void initialize(URL location, ResourceBundle resources) {
//Using Simple Property to store and list course data
id.setCellValueFactory(new PropertyValueFactory<Course, Integer>("id"));
courseName.setCellValueFactory(new PropertyValueFactory<Course, String>("courseName"));
courseContent.setCellValueFactory(new PropertyValueFactory<Course, String>("courseContent"));
addedBy.setCellValueFactory(new PropertyValueFactory<Course, String>("addedBy"));
courseIP.setCellValueFactory(new PropertyValueFactory<Course, String>("courseIP"));
courseTimeStamp.setCellValueFactory(new PropertyValueFactory<Course, Date>("courseTimeStamp"));
coursesTable.setItems(coursesList);
}
}