3 Replies - 353 Views - Last Post: 19 June 2020 - 05:03 AM Rate Topic: -----

#1 baki2001   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 11-June 20

Observable Patterns and interacting Frames

Posted 18 June 2020 - 09:46 PM

I am trying to build a 911 dispatcher application that displays messages to different frames when written on a single "Main Frame" using Observable Patterns. I know how Observable Patterns work and the different interfaces and classes it should have but I just don't know how to go on about this or where to start.

Can anyone help.
Is This A Good Question/Topic? 0
  • +

Replies To: Observable Patterns and interacting Frames

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5549
  • View blog
  • Posts: 14,557
  • Joined: 18-April 07

Re: Observable Patterns and interacting Frames

Posted 18 June 2020 - 11:07 PM

In these situations I typically start with the classes that are going to do the listening. So you would create your frame objects and have them use the event interface so that all frames have the same event code. Then in the main frame you can create a list of instances of the other frames.

For instance, I have one frame called "Frame911Police" and it implements an interface called "IHandleCaller" which has a method called "handleCall()" and takes a parameter like "callCase" that might talk about the type of case it is (domestic violence, burning building, medical emergency, robbery etc). You would have "Frame911Ambulance" and "Frame911Fire" that all implement the same interface.

Then in your main frame called "Dispatcher" you will maintain a list of type "IHandleCaller".

List<IHandleCaller> caseList = new List<IHandleCaller>();



Then you would create a method which loops through this list whenever you want to publish something happened. It would loop through the list, calling each class' handleCall() method, giving it the callCase.

CallCase aCase = new CallCase("Medical Emergency", "Heart Attack", "John Smith", 31);

for (int i = 0; i < caseList.size(); i++) {
   caseList[i].handleCall(aCase);  //<-- Here we are calling all listeners and give it the case that just happened. Each class (in our case frame) can do what they like with the info.
}



Lastly, you need a way to have frames to become listeners to the event. So naturally after creating your frame, you can add them to the caseList.

Hopefully that is enough to get you started to a working example that you can then show us and we can help further if you are stuck.

This post has been edited by Martyr2: 18 June 2020 - 11:09 PM

Was This Post Helpful? 1
  • +
  • -

#3 baki2001   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 11-June 20

Re: Observable Patterns and interacting Frames

Posted 18 June 2020 - 11:36 PM

Ok this is slowly starting to make sense but I don't know where exactly to implement these so let me tell you a little bit more about the format we were told to follow. There are 2 interfaces called Observable and Observer and five other classes called MessagePanel, MessageData, Primary Console(concrete Observabe/Subject), CommsUnit(concrete Observer) and finally EMSCommsViewer which is used to display all of this. This is how my professor explained it but it still doesn't make sense to me: "The MessagePanel is what CommsUnit uses to display the data sent to it via Message objects. Update method in CommsUnit receives a Message object and this message object has a channel attached to it. The CommsUnit checks to see if the message object's channel matches the channels it monitors, and if it does it displays it appropriately."

So from this what I understand is that CommsUnit HAS-A MessagePanel and MessagePanel IS-A JPanel. PrimaryConsole and CommsUnit both use the MessageData class - PrimaryConsole uses it to send A message, CommsUnit receives Message objects and processes them. But I just don't know how to go on about doing this. Observable Patterns is all new to me and we weren't taught about it.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3698
  • View blog
  • Posts: 16,952
  • Joined: 20-September 08

Re: Observable Patterns and interacting Frames

Posted 19 June 2020 - 05:03 AM

https://docs.oracle....geListener.html
https://docs.oracle....l/Observer.html

The above links could be useful even if the second is deprecated. It might even be possible to use the first in your solution, giving you two extra pluses:

a. showing that you can reuse existing best-practice software (essential skill for serious developers)
b. learning about existing Java in greater depth
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1