Member-only story
Demo GUI With Java Swing

This demo app is a graphical user interface (GUI) with Java that uses a design pattern called Model View Controller (MVC) and also incorporates an SQLite database.
I recommend having an understanding of classes and objects work in Java before attempting to use this demo or begin learning how to use Swing to build GUIs. If you already understand concepts of object-oriented programming, you could probably find a short YouTube video to get caught up with the Java syntax.
Java Swing
Build a GUI (graphical user interface) is super easy in Java. Swing is a lightweight set of components that work almost completely the same on all platforms. You can refer to the Swing docs for more information about what’s going on inside the program.
The Structure Of The App
This demo is a super simple finance application that contains 5 java classes.
- Model: represents the data in the application, nothing else.
- View: displays the data from the Model and sends user interactions to the Controller.
- Controller: contains both the Model and View, sends data from the model to interact with the View.
- RunFinanceProgram: contains the main method to run the program, initiates the database, and creates Model, View, and Controller objects and then initializes the Controller to startup the app.
- Math: contains a simple round() method which rounds decimals to two places.
Add Your Own Features
I encourage you to go download the .zip, import into an IDE of your choice (I use Eclipse), add new fields to the Model, use the methods I’ve already used to insert the new fields into the database, and then add those new fields to the View, and then make them accessible by adding a new event in the Controller.
Also try adding methods to the Math class to do some analysis on values within the program.
By adding your own features to the program, you’ll learn much more about how to build a GUI with Swing.
Originally published at https://austinhoward.tech on November 12, 2019.