@ -1,14 +0,0 @@ | |||
package com.jesuspinar.miobjeto; | |||
import javafx.fxml.FXML; | |||
import javafx.scene.control.Label; | |||
public class HelloController { | |||
@FXML | |||
private Label welcomeText; | |||
@FXML | |||
protected void onHelloButtonClick() { | |||
welcomeText.setText("Welcome to JavaFX Application!"); | |||
} | |||
} |
@ -0,0 +1,51 @@ | |||
package com.jesuspinar.miobjeto.controller; | |||
import com.jesuspinar.miobjeto.model.PersonE; | |||
import com.jesuspinar.miobjeto.serializable.controller.ObjReader; | |||
import com.jesuspinar.miobjeto.serializable.model.People; | |||
import com.jesuspinar.miobjeto.serializable.model.Person; | |||
import javafx.collections.FXCollections; | |||
import javafx.collections.ObservableList; | |||
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.File; | |||
import java.net.URL; | |||
import java.util.ResourceBundle; | |||
public class DataTbl implements Initializable { | |||
@FXML | |||
public TableView<PersonE> tvData; | |||
@FXML public TableColumn<PersonE, Integer> idColumn; | |||
@FXML public TableColumn<PersonE, String> nameColumn; | |||
@FXML public TableColumn<PersonE, Integer> ageColumn; | |||
private People data; | |||
private ObservableList<Person> getPeople() { | |||
File file = new File("person.bin"); | |||
ObservableList<Person> people = null; | |||
if (file.exists()) { | |||
//Get data form the bin | |||
data = (People) ObjReader.read(file); | |||
System.out.println(data.toString()); | |||
people = FXCollections.observableArrayList(data.getData()); | |||
} | |||
return people; | |||
} | |||
@Override | |||
public void initialize(URL location, ResourceBundle resources) { | |||
//Add data to colum | |||
idColumn.setCellValueFactory(new PropertyValueFactory<>("idColumn")); | |||
nameColumn.setCellValueFactory(new PropertyValueFactory<>("nameColumn")); | |||
ageColumn.setCellValueFactory(new PropertyValueFactory<>("ageColumn")); | |||
tvData.setItems(getPeople()); | |||
} | |||
} |
@ -0,0 +1,52 @@ | |||
package com.jesuspinar.miobjeto.model; | |||
import javafx.beans.property.SimpleIntegerProperty; | |||
import javafx.beans.property.SimpleStringProperty; | |||
public class PersonE { | |||
private SimpleIntegerProperty id; | |||
private SimpleStringProperty name; | |||
private SimpleIntegerProperty age; | |||
public PersonE(int id, String name, int age) { | |||
this.id = new SimpleIntegerProperty(id); | |||
this.name = new SimpleStringProperty(name); | |||
this.age = new SimpleIntegerProperty(age); | |||
} | |||
public int getId() { | |||
return id.get(); | |||
} | |||
public SimpleIntegerProperty idProperty() { | |||
return id; | |||
} | |||
public void setId(int id) { | |||
this.id.set(id); | |||
} | |||
public String getName() { | |||
return name.get(); | |||
} | |||
public SimpleStringProperty nameProperty() { | |||
return name; | |||
} | |||
public void setName(String name) { | |||
this.name.set(name); | |||
} | |||
public int getAge() { | |||
return age.get(); | |||
} | |||
public SimpleIntegerProperty ageProperty() { | |||
return age; | |||
} | |||
public void setAge(int age) { | |||
this.age.set(age); | |||
} | |||
} |
@ -0,0 +1,28 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<?import javafx.scene.control.*?> | |||
<?import javafx.scene.layout.*?> | |||
<?import javafx.geometry.Insets?> | |||
<GridPane xmlns="http://javafx.com/javafx" | |||
xmlns:fx="http://javafx.com/fxml" | |||
fx:controller="com.jesuspinar.miobjeto.controller.DataTbl" | |||
alignment="CENTER" | |||
hgap="10" vgap="10" | |||
> | |||
<padding> | |||
<Insets top="25" right="25" bottom="10" left="25"/> | |||
</padding> | |||
<TableView fx:id="tvData" layoutX="20" layoutY="20" | |||
prefWidth="600" prefHeight="400"> | |||
<columns> | |||
<TableColumn fx:id="idColumn" prefWidth="75.0" text="Id" /> | |||
<TableColumn fx:id="nameColumn" prefWidth="75.0" text="Name" /> | |||
<TableColumn fx:id="ageColumn" prefWidth="75.0" text="Age" /> | |||
</columns> | |||
<columnResizePolicy> | |||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> | |||
</columnResizePolicy> | |||
</TableView> | |||
</GridPane> |