Swing App question

J

Java and Swing

I have a swing app I am working on and I have the following GUI classes
with the given hierarchy:

MainPanel
BuddyListPanel
ChatPanel
LogPanel
MsgPanel

So, MainPanel contains a BuddyListPanel and a ChatPanel. ChatPanel
contains a LogPanel and a MsgPanel.

When MainPanel is created an instance of the ClientModel is given to
it, so that it can register with the model, etc.

Problem is, when someone types a message into the textfield in a
MsgPanel, and clicks the "Send" button the message needs to be
sent out. However, the MsgPanel has no knowledge of who the receiver
of the message is (i.e. the IP address of the buddy receiving the
message, etc).

How can I work this out? I don't want to pass the ClientModel from the
MainPanel to ChatPanel to the MsgPanel...that seems wrong.

Thanks in advance.
 
O

Oliver Wong

Java and Swing said:
I have a swing app I am working on and I have the following GUI classes
with the given hierarchy:

MainPanel
BuddyListPanel
ChatPanel
LogPanel
MsgPanel

So, MainPanel contains a BuddyListPanel and a ChatPanel. ChatPanel
contains a LogPanel and a MsgPanel.

When MainPanel is created an instance of the ClientModel is given to
it, so that it can register with the model, etc.

Problem is, when someone types a message into the textfield in a
MsgPanel, and clicks the "Send" button the message needs to be
sent out. However, the MsgPanel has no knowledge of who the receiver
of the message is (i.e. the IP address of the buddy receiving the
message, etc).

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
 
J

Java and Swing

Oliver said:
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"?
 
O

Oliver Wong

Java and Swing said:
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...

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,247
Latest member
crypto tax software1

Latest Threads

Top