package com.example.javafx;
|
|
import javafx.collections.FXCollections;
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.Initializable;
|
|
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.util.ResourceBundle;
|
|
|
|
public class StudentController implements Initializable {
|
|
@FXML
|
|
private TableView<StudentModel> tbData;
|
|
@FXML
|
|
public TableColumn<StudentModel, Integer> studentId;
|
|
@FXML
|
|
public TableColumn<StudentModel, String> firstName;
|
|
@FXML
|
|
public TableColumn<StudentModel, Integer> studentAge;
|
|
|
|
@Override
|
|
public void initialize(URL url, ResourceBundle resources) {
|
|
File file = new File("C:\\ADA\\FichPersonas.dat");
|
|
tbData = new TableView<>();
|
|
try {
|
|
leerFichData(file, tbData);
|
|
studentId.setCellValueFactory(new PropertyValueFactory<>("studentId"));
|
|
firstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
|
|
studentAge.setCellValueFactory(new PropertyValueFactory<>("studentAge"));
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
/*
|
|
new StudentModel(1,"Juan","Martínez"),
|
|
new StudentModel(2,"Perico","López"),
|
|
new StudentModel(3,"Andrés","Gomez")
|
|
));*/
|
|
}
|
|
|
|
public static void leerFichData(File fichero, TableView<StudentModel> tbData) throws IOException {
|
|
FileInputStream filein = new FileInputStream(fichero);
|
|
DataInputStream dataIS = new DataInputStream(filein);
|
|
int i;
|
|
String n;
|
|
int e;
|
|
try {
|
|
while (true) {
|
|
i = dataIS.readInt();
|
|
n = dataIS.readUTF();
|
|
e = dataIS.readInt();
|
|
tbData.setItems(FXCollections.observableArrayList(
|
|
new StudentModel(i,n,e)));
|
|
}
|
|
}catch (EOFException error){
|
|
System.out.println("error");
|
|
}
|
|
dataIS.close();
|
|
}
|
|
|
|
}
|