Code Monkey home page Code Monkey logo

crud-grazioso-javafx's Introduction

JavaFX CRUD App

demo

This CRUD application is designed to intake and track an animal's training status for a mock company, Grazioso.

Technologies

  • Java
  • JavaFX
  • FXML

Features

  • Serialization / deserialization
  • Sortable table view
  • Input validation
  • User interface
  • MVC architecture
  • CRUD

Purpose

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.

What I Learned

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.

Code Snippets

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

Relevant Docs and Resources

crud-grazioso-javafx's People

Contributors

dorian-adams avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.