Saturday, January 26, 2013

Reminders: a JavaFX and JPA demo application

This time around, I wrote a somewhat more serious demo application, called 'Reminders' (guess what it does). It's cool in oh so many ways:

  • JPA is used for persistence, together with bean validation to check constraints before persisting an entity.
  • FontAwesome is used for its cool icons. They look great and because they are text, you can easily change their size or color.
  • Advanced (from my perspective at least) CSS is used to completely change the look and feel of ListView and Button nodes.
  • It has neat dialog windows. The code for these should be pretty reusable.
  • It includes a 'location picker' written in JavaScript, but seamlessly incorporated into JavaFX thanks to the WebView.
  • It uses JFXtras for its CalendarTextField, which, truth be told, works great but looks hella-ugly.

Screenshots:






How to use this application:

First, you need to set up the database. There's two ways to do this:
  1. In NetBeans, go to the Services window. Under Databases, right-click Java DB and create a new database with the following settings:
    • Name: Reminders
    • Username: APP
    • Password: APP
  2. Or create your own empty database and edit persistence.xml to use this database. Make sure you add the correct JDBC driver to the project.
Then, simply run the application. The database schema will be created upon first use. Once this is done, you can edit persistence.xml to set the table generation strategy to none.

The required libraries are found in the lib folder. You will also need EclipseLink and the Java DB Driver (if you chose option 1), but NetBeans already has those bundled with it.

Source code:


I hope you have fun with this. Let me know if something isn't working for you, or if you can't figure out the source code. As always, you can find me at myfirstname dot mylastname at icloud dot com (I already have plenty of spam, thanks).

7 comments:

  1. Does this example work from browsers too?

    ReplyDelete
  2. Honestly, I've never tried it, as I couldn't care less about it. My personal opinion on applets is that they should have been deprecated over a decade ago. All they do is give Java a bad name anyway.

    ReplyDelete
  3. Very nice! I was looking for this! But when i doesn't start the server in Netbeans the app doesn't work (derby's localhost doesn't start).

    How can i start the server by launching from a .jar file without starting the server?

    Thanks.

    ReplyDelete
    Replies
    1. See the "How to use this application" section above. You can run from a .jar file just fine, as long as you set up the database first.

      Delete
  4. If it's a problem using it outside of Netbeans, you need to use another driver for Derby and another url to use it outside of netbeans.

    Search this in Google, you'll find plenty of solutions.

    ReplyDelete
    Replies
    1. Thanks for the tip, but I can run it just fine outside of NetBeans, by double-clicking the jar-file.

      Delete
  5. Muchas gracias por el aporte, yo tambien estoy trabajando con java fx y JPA 2.0 me ha servido de mucho

    ReplyDelete