>I have a swing app I am working on and I have the following GUI classes
> with the given hierarchy:
[quoted text clipped - 18 lines]
>
> How can I work this out?
Traditionally, you have one message/log panel per buddy, so that's one
way to avoid this whole problem.
Otherwise, I'd just have the "Send" button pass the text the user
entered in to the model. The model knows which buddy is currently selected,
and it is now receiving the text to be sent to that buddy, so the model can
take care of associating the message with a specific buddy, sending it to
whatever object handles the TCP/IP communications (possibly itself?), and
notifying the log that a new entry has been added (recording the outgoing
message).
> I don't want to pass the ClientModel from the
> MainPanel to ChatPanel to the MsgPanel...that seems wrong.
The way I've visualized it, you have a your ClientModel, and all these
GUI controls which registered themselves with the model. There's no passing
of the client model around at event-handling time. The model gets passed
around at construction time so that everyone can register themselves, but
that's it. From there, the user clicks on stuff, which generates events,
which your GUI controls intercept, and translate into method calls to the
model they registered with.
- Oliver
Java and Swing - 04 Oct 2006 18:35 GMT
> Traditionally, you have one message/log panel per buddy, so that's one
> way to avoid this whole problem.
well the client model keeps a map of buddys that connect. when a new
message is sent in from a buddy, a new ChatPanel is created for that
conversation. currently I am passing client model around...which i
don't like...hence what I am trying to figure out.
So perhaps the MainPanel should fire a "Open Chat" event, so a new chat
panel opens up...and the model stores this information. The
ClientModel stores Buddy objects....so shoudl the buddy objects store
"chatOpen = true/false"?
Oliver Wong - 04 Oct 2006 18:53 GMT
>> Traditionally, you have one message/log panel per buddy, so that's
>> one
[quoted text clipped - 7 lines]
> So perhaps the MainPanel should fire a "Open Chat" event, so a new chat
> panel opens up...
Yes, this is what I meant by one message/log panel per buddy.
> and the model stores this information. The
> ClientModel stores Buddy objects....so shoudl the buddy objects store
> "chatOpen = true/false"?
I'm assuming you're making an instant messaging client. I'd have the
each buddy window registered with a main window (where the buddy list
appears), and the main window registered to the model, and the model is
registered to whatever it is that's handling the networking stuff. When a
packet comes in, the a signal is sent to the model to translate it into an
application level event, such as a new message coming from a specific buddy.
The model updates itself with this info, and notifies all of its listeners.
One such listener is the main window. The main window checks its list of
listeners to find out if there's already a window associated with that
buddy. If so, it notifies that window of the event. Otherwise, it creates a
window associate with the buddy, and immediately notifies it.
- Oliver