Link to home
Create AccountLog in
Avatar of drewmore44

asked on

Java program architecture / flow control

I have 2 separate GUI windows. The first displays a list of list of all employees at a firm, and the user selects those that are working a particular shift. The second GUI displays a table with a line for each employee selected in the first GUI, and several columns into which the user inputs different pieces of data pertaining to that shift. That data is then used by other (non-GUI) classes to compute further data.

My question now pertains to the general architecture of the program. As I understand things, I think I want to have 2 separate JFrame classes for the two GUIs, along with the (non-GUI) classes that store and compute data entered in through the GUI. I then want the main class to act as "quarterback," launching the GUIs at appropriate times and implementing the other classes as needed to perform the various calculations.

First off, is this general strategy in line with best practices? Assuming that it is: How can I use the main method to control the flow of the application? There is a large button at the bottom of the first GUI that the user clicks when they are done setting the schedule. When I run the main method now, it launches the first GUI and does everything else (e.g. getting the schedule collections, which haven't been populated yet) at the same time - how do I tell it to launch the first GUI, then wait until that button is clicked, then launch the second GUI (passing to it the collection of employee objects assembled by the first GUI).

I think I want to use a listener, but I'm not really sure how to do so: do I declare one n the main method (and if so, how do I tell it to listen to that particular button within the GUI class), or do I declare it in the GUI class and reference it somehow in the main method?

I'm also a little foggy on the concept of interfaces, but I have a suspicion that one might be useful here in "interfacing" (for lack of a better word) the different classes and controlling the flow of the program. Might that be true?
Avatar of CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

I think you might benefit from looking at the CardLayout. It could be tidier than spawning new windows and better for flow
Avatar of drewmore44


Hmm, how would using CardLayout differ from the approach I'm taking (and having problems with), as described here

Could you briefly walk me through how to implement a CardLayout?
Avatar of zzynx
Flag of Belgium image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Good luck and thanx 4 axxepting