• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI, Search and Events

 
Mickey Mulligan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heya, I've nearly finished my B&S assignment, but I'm a little stuck with the search functionality on the GUI end.

I have a 'search' button on my GUI which pops up a SearchDialog (extending JDialog), the user will input details here and click 'find records'.

My problem is how to transmit these details back to the MainWindow (a JFrame), so it can act on them.

So, from a design perspective, what's the best way to approach this?

I'm considering something like:



This would add the listener to the 'find records' button in the SearchDialog and the above method would be called from the MainWindow class.

I would have a private SearchListener in MainWindow to update the JTable with the search results.

Any opinions on this?
[ March 18, 2007: Message edited by: Mickey Mulligan ]
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mickey

Well you can do like this
After you collect the search information you can notify your controller (preferably with an event), the controller knows your model so it can inform it to load all the records which are matching your search information. After the model does this it notifies the view which uses its (UI) mechanisms to render the changes.
After all this are done you can run in the kitchen and prepare your self a jelly sandwich.

Regards M.
 
Vincent Li
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

That sounds way too complicated. Why don't you just add some accessors (getter) methods to your dialog to retrieve the information? That's what I usually do, since your dialog is modal, isn't it? Similarly, have some setters to initialize the dialog with default/previous values if you like. Something like this:



None of those complex intertwined Listeners!

--
Vince
SCJP(1.4), SCWCD(1.4), SCJD (waiting for results...)
 
Mickey Mulligan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks folks! I've decided to do what Vincent recommended, this approach eliminates my design worries.
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yesterday my version used some observer stuff. In the morning I went into problems with that and now I have also such getter methods and I did not have read Li's comment when I did the changes.

So I use also his alternative.

Br, Lucy
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

This is true "an observer" is only a little bit more complicated than a simple method call, but this pays its price - you lose the flexibility and you increase the dependencies between the involved components.
I'll get a snippet from Vincent post to exemplify this :

since your dialog is modal, isn't it? Similarly, have some setters to initialize the dialog with default/previous values if you like. Something like this:


Your theory is true only if you use a modal search dialog, but if you decide to make an search in a non modal(or in a panel) you'll get some problem.
You must change not only the view layer you also must change the model and the controller.


Regards M.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic