GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Design question - events or observer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Design question - events or observer" Watch "Design question - events or observer" New topic
Author

Design question - events or observer

Gene Hilpert
Ranch Hand

Joined: May 22, 2002
Posts: 51

I'm writing a java desktop application to learn java (it is an application to handle boy scout memberships)
and have hit design question.
I have a main jframe that has a jtable that holds checkbook records,
then I have another jframe with another jtable that will hold budget items for a check.
Ex. in the first table
check #100, summer camp, 2008, $1000.00
check #101, charter fees, 2008, $650.00
in the second table you have for check #100
200.00, gas
800.00, fees
for check #101
650.00, fees

What I want is when you scroll thru the first table the second table change as well.

Ex. when you are in the first record in the first table(#100) the second one shows
200.00, gas
800.00, fees
when you scroll to the second record the first table(#101) the second one shows
650.00, fees

I'm looking at two ways to do this
1) using events
2) using observable and observer

Any ideas on the best way or a third way?

Also there will be other jframes that will do things similar to the second jframe
(what members accounts are debited or credited with this check.)( I put the tables in
separate frames to be able to turn then off)

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39076
    
  23
Are you sure you are not describing a database? Sounds like the sort of thing people do every day in SQL.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
In fact, events and the Observer pattern are basically the same thing. And they sound like a good solution to your problem - updating one part of the GUI based on actions in a different part.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Gene Hilpert
Ranch Hand

Joined: May 22, 2002
Posts: 51

I'm using embedded Javadb as a DB.
The queries are no problem. I just wanted to know if I was missing something better to communicate between the frames.

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39076
    
  23
No for communication between frames, events are what you need.
 
GeeCON Prague 2014
 
subject: Design question - events or observer