How should a database-oriented Java Swing be developed?

I am writing a database oriented Java Swing application for a while.

The GUI and DAO code fall into a large tree, for example:

JFrame | JTabbedPane | +--------------------+----------------------+-------------+ | | | | JPanel1 JPanel2 JPanel3 JPanel4 | | | | JButtons--JTable1 JTextFields--JButton JTable2 JDialog--JTable3 i! i! i! i! Model1 Model2 Model3 Model4 | | | | +------------+-----------+---------+-------------------+ | DataAccessObject 

The application has several types, some contain a JTable for displaying data, and some contain a dialog with a form for editing or adding data.

I have a DataAccessObject with a JDBC connection. I use several models (extends AbstractTableModel ) to connect the views (forms or tables) with the DAO.

In my first version, I implemented DAO as Singleton, then I found out that it is an anti-pattern and uses Dependency Injection, so I initialize the DAO first and then insert it into the constructor of all models. Then I initialize the JFrame and insert the model reference in the constructor in the hole GUI tree.

Passing model links through a GUI tree hole feels very awkward, but I know that I have good control over dependencies. But is there any better design I could use for database-oriented Java Swing applications with many data views that need a database-connected model?

+4
source share
1 answer

I would also support Shakedown's comment. It is all about layers. Divide your code into layers / levels.

Since you talked about Injection Dependency, I suggest you take a look at the Spring Rich Client framework to understand how good Swing applications can be developed / developed.

+1
source

All Articles