For example, you have a program where you first sign in, then you have a window (errm, frame ) open, in the frame there's a drop-down menu, each item on the menu opens a new frame, similar to the "tools" menu in your web-browser, as an example.
Now does the "sign-in" screen and each item on the menue get programmed in a separate class, where clicking on an item creates a new object of that class and has the code to display it in its constructor? Or is that not how you write a multiple-window program?
It's a common practice to have a Controller object that orchestrates the goings on between windows and the business/data side of an application. One common pattern is called "Model View Controller". Googling for that will find some technical and rather advanced discussions, so let's try to approach it more gently.
At a high level it might look like:
The Model here is some Plain Old Java Object that maybe checks the userid & password against a database. The Controller has the logic to decide what to do when authenticate succeeds or fails.
Showing a window calling the Controller skips over a lot of details - buttons and listeners and such. It sounds like you're getting comfortable with those things. Just make a button event handler that calls the Controller.
Other menu options should do much the same thing - just tell the Controller that something happened. I like a description of the controller "interpreting user gestures", messages like "The user hit this button" or at a slightly higher level "The user wants to close the application now"
Does that kind of thing make sense? Scroll down to the OO, UML, etc. forum for more detailed discussions of designs like this.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jul 21, 2007
Thanks a lot for the answers...
It's just when you tackle that first small project where design actually matters, it's scary how there are a million ways to do something right, and a billion ways to do it wrong, and you gotta pick one.