This CRUD application is designed to intake and track an animal's training status for a mock company, Grazioso.
- Java
- JavaFX
- FXML
- Serialization / deserialization
- Sortable table view
- Input validation
- User interface
- MVC architecture
- CRUD
This project began as a class assignment that I expanded upon to try my hands at something more complex. The original assignment involved creating a Java application that took input from the console and managed animals for a mock company called Grazioso. To make this into a full-featured CRUD app, I added a UI via JavaFX, serialization/deserialization to save data across uses, and more. My goal was to create a more professional and complete program for better practice.
In working on this project, I honed three valuable skills: research, implementing professional design patterns, and even Android development. At the onset of this project, I had no previous exposure to JavaFX. To increase my familiarity, I utilized various tools provided by the IDE and consulted official documentation when more in-depth research was required. As such, I'm now more confident in adapting to new libraries quickly. The design architecture I used, Model-View-Controller, can be applied to various languages and applications. Implementing MVC in this project was a great lesson in the benefits of creating highly focused and organized components. The result is a very easy codebase to read, expand upon, and manage. Surprisingly, I've also found that many of the practices and techniques used in JavaFX are highly applicable to Android development, which I look forward to exploring soon.
Initialize the table:
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
try {
AnimalList.initializeList();
colName.setCellValueFactory(data -> data.getValue().animalNameProperty());
colSpecies.setCellValueFactory(data -> data.getValue().animalSpeciesProperty());
colLocation.setCellValueFactory(data -> data.getValue().locationProperty());
colName.setCellFactory(TextFieldTableCell.forTableColumn());
colSpecies.setCellFactory(TextFieldTableCell.forTableColumn());
colLocation.setCellFactory(TextFieldTableCell.forTableColumn());
tableView.setItems(AnimalList.allAnimals);
} catch(Exception e) {
e.printStackTrace();
}
// Set double-click event.
tableView.setOnMouseClicked(click -> {
if (click.getClickCount() == 2) {
editAnimalWindow(getSelection());
}
});
}
Date validation method:
private void validDate (DatePicker date) {
LocalDate today = LocalDate.now();
date.setValue(today);
date.setOnAction(e -> {
if (today.isBefore(date.getValue())) {
raiseWarning(date);
date.setValue(today);
} else {
suppressError();
}
});
}
Serialize:
/** Serializer is static-only, and not to be instantiated. */
private Serializer() {}
public static void serialize(ObservableList<RescueAnimal> observableListAnimals) throws IOException {
try(var serializer = new ObjectOutputStream(new FileOutputStream(PATH, false))) {
ArrayList<RescueAnimal> convertedList = new ArrayList<>(observableListAnimals);
serializer.writeObject(convertedList);
}
}