Browse Source

act2

main
Jesus 2 years ago
parent
commit
d865d218a2
7 changed files with 143 additions and 19 deletions
  1. +1
    -1
      pom.xml
  2. +7
    -4
      src/main/java/com/jesuspinar/miobjeto/App.java
  3. +0
    -14
      src/main/java/com/jesuspinar/miobjeto/HelloController.java
  4. +51
    -0
      src/main/java/com/jesuspinar/miobjeto/controller/DataTbl.java
  5. +52
    -0
      src/main/java/com/jesuspinar/miobjeto/model/PersonE.java
  6. +4
    -0
      src/main/java/com/jesuspinar/miobjeto/serializable/model/People.java
  7. +28
    -0
      src/main/resources/com/jesuspinar/miobjeto/data-tbl.fxml

+ 1
- 1
pom.xml View File

@ -60,7 +60,7 @@
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.jesuspinar.miobjeto/com.jesuspinar.miobjeto.HelloApplication</mainClass>
<mainClass>com.jesuspinar.miobjeto/com.jesuspinar.miobjeto.App</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>


src/main/java/com/jesuspinar/miobjeto/HelloApplication.java → src/main/java/com/jesuspinar/miobjeto/App.java View File

@ -7,16 +7,19 @@ import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
public class App extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("student-list.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 400, 400);
stage.setTitle("Data");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}

+ 0
- 14
src/main/java/com/jesuspinar/miobjeto/HelloController.java View File

@ -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!");
}
}

+ 51
- 0
src/main/java/com/jesuspinar/miobjeto/controller/DataTbl.java View File

@ -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());
}
}

+ 52
- 0
src/main/java/com/jesuspinar/miobjeto/model/PersonE.java View File

@ -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);
}
}

+ 4
- 0
src/main/java/com/jesuspinar/miobjeto/serializable/model/People.java View File

@ -23,6 +23,10 @@ public class People implements Serializable {
return true;
}
public ArrayList<Person> getData() {
return data;
}
@Override
public String toString() {
return data.toString();


+ 28
- 0
src/main/resources/com/jesuspinar/miobjeto/data-tbl.fxml View File

@ -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>

Loading…
Cancel
Save