|
|
@ -7,7 +7,9 @@ import javafx.scene.control.TableColumn; |
|
|
|
import javafx.scene.control.TableView; |
|
|
|
import javafx.scene.control.cell.PropertyValueFactory; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.net.URL; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.util.ResourceBundle; |
|
|
|
|
|
|
|
public class StudentController implements Initializable { |
|
|
@ -23,16 +25,48 @@ public class StudentController implements Initializable { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void initialize(URL url, ResourceBundle resourceBundle) { |
|
|
|
studentId.setCellValueFactory(new PropertyValueFactory<>("studentId")); //<_El valor deberá ser el mismo!! |
|
|
|
firstName.setCellValueFactory(new PropertyValueFactory<>("FirstName")); |
|
|
|
lastName.setCellValueFactory(new PropertyValueFactory<>("LastName")); |
|
|
|
tbData.setItems(FXCollections.observableArrayList( |
|
|
|
new StudentModel(1, "student1", "lastname1"), |
|
|
|
new StudentModel(2, "student2", "lastname2"), |
|
|
|
new StudentModel(3, "student3", "lastname3"), |
|
|
|
new StudentModel(4, "student4", "lastname4"), |
|
|
|
new StudentModel(5, "student5", "lastname5") |
|
|
|
)); |
|
|
|
|
|
|
|
/*Deserializar el archivo hecho en 8.2 por el fichero .dat del primer ejercicio */ |
|
|
|
String fileToParse = "C:\\Users\\jandr\\Desktop\\Acceso a datos\\Container Ficheros\\FichPersona.dat"; |
|
|
|
File file = new File(fileToParse); |
|
|
|
|
|
|
|
/*Creamos modelo objeto*/ |
|
|
|
StudentModel student; |
|
|
|
|
|
|
|
/*Leemos archivo*/ |
|
|
|
FileInputStream fIn; |
|
|
|
try { |
|
|
|
fIn = new FileInputStream(file); |
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
ObjectInputStream dataIS; |
|
|
|
try { |
|
|
|
dataIS = new ObjectInputStream(fIn); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
while (true) { |
|
|
|
/*Cogemos los datos y rellenamos las celdas*/ |
|
|
|
student = (StudentModel) dataIS.readObject(); |
|
|
|
studentId.setCellValueFactory(new PropertyValueFactory<>("studentId")); |
|
|
|
firstName.setCellValueFactory(new PropertyValueFactory<>("FirstName")); |
|
|
|
lastName.setCellValueFactory(new PropertyValueFactory<>("LastName")); |
|
|
|
tbData.setItems(FXCollections.observableArrayList( |
|
|
|
new StudentModel(student.getStudentId(), student.getFirstName(), student.getLastName()) |
|
|
|
)); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (ClassNotFoundException | IOException error) { |
|
|
|
System.out.println(error.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
//Cerramos |
|
|
|
try { dataIS.close(); } catch (IOException e) { throw new RuntimeException(e); } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |