Creating an application with multiple panels

Hey Everyone, this isnt really game related but I am having some problems creating a Java Swing application with multiple jpanels.

I am using the CardLayout which works great for switching between screens however my issue is with passing data. For example I have a MainPanel with a MenuScreen and SearchScreen, on my MenuScreen I have a textbox which one enters a phone number and hits search. This should then switch the screen to the SearchResult screen which will display the results of a SQL Query using the number provided on the MenuScreen.

I am wondering, if I am using a cardlayout on the MainPanel which I call in order to switch screens, how do I pass the new screen the phone number value?

Values of your program should be independent of your GUI stuff. The GUI is just for displaying the data.

Right, I kind of realized i was mixing these a bit too much just a bit ago and decided I would essentially create a model which I can manipulate values for and then the panels can use the model to display what they need to.

My only issue with that is, lets say I have a model which has a customer. The person using the software searches the phone number “555-5555” and when he hits search it sets the Model’s customer objects phone number to “555-5555” and takes him to the SearchResult screen, this screen will use that customer objects phone number to perform the search and display it. All is good, and lets say he goes back to the main screen and searches again, the customers phone number will change and therefore the search will still work.

I think?

Any problem with this idea?

Looks good.

Create a some kind of controller. Your GUI’s job are only 2, feed it with input and display its output.