Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Swing App question

Thread view: 
Java and Swing - 04 Oct 2006 17:36 GMT
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.
Oliver Wong - 04 Oct 2006 17:44 GMT
>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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.