Recently I began an adventure with JAVA. I am looking for a guidance on design patterns and overall architecture of JAVA project.
I'm working on a small application project as university assignment. It's a typical learning-by-doing project. The app has GUI made up of Swing elements and few additional classes.
The problem that I face is realted with lack of idea of how to tie it all together. Specifically I face following problems:
Problem 1
Login problem - I have custom User class. I keep the current_user as property of main JFrame.
During GUI loading - I would like to check if the user is signed in. Also - on specific actions - I would like to sign out user.
Currently I solve both problems by going all the way to mainFrame.current_user
property. But I feel that's bad approach. As there can only be one user in the application - there should be a way of defining globally visible methods like current_user
, user_signed_in()
or sign_out(current_user)
without calling JFrame. Is my feeling correct?
Problem 2
During initialization of GUI I am creating a JTable that is displaying data downloaded from web with custom WebRequest class. JTable data is kept in Object data[][]
a property of table model extending AbstractTableModel. Right now I am building the data model when the application starts - meaning calling a WebRequest, initializing Table and it's model.
Right now I would like to change this behavior. I would like to display empty JTable when the application starts - and call the WebRequest only by clicking JMenuItem refresh button.
How to approach it? At the moment my only idea is to have JTable data model and call a one of it's methods - something like refresh()
. This method should call WebRequest and update JTable. But for this I have to get from JMenuItem to JTable that is in completely different place.
What can be better approach here? Again - there can be only one Data model to call in the app - so maybe a similliar problem to Problem 1?
Also if you know a good reading on design patters, or good open source repos to study - I would really appreciate any suggestions.