Re: HELP! Updating a 'global' variable in a chat application
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 12/09/03
- Next message: Adam: "Re: Extended break"
- Previous message: Navigator: "Re: Can someone please tell me what this means?"
- In reply to: E-Wiz: "HELP! Updating a 'global' variable in a chat application"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 09 Dec 2003 06:35:05 GMT
"E-Wiz" <sonique55107@yahoo.com> wrote in message
news:9e6e0c61.0312081604.18c82483@posting.google.com...
>
> I am having trouble with an application i am building and
> would love any helping hands.
>
> Here's what i am trying to do:
>
> I have a chat application that works with sockets.
>
> I want the admin to have access to a variable that is specific
> to each person in the chatroom. To be more specific, I define
> a variable x as follows:
>
> public class Global {
> public static int x =0;
> }
>
> And then i want to update x through the following
> method:
>
> public void doAction(ActionEvent event)
> {
> if (event.getSource() == initializeButton)
>
> {
> Global.x=1;
> }
> ......
>
By declaring this variable 'static' you are ensuring there is a single copy
of it shared by all instances of this class. If one instance updates it, the
previous value - for all instances - is overwritten. However, this is not
the source of your problem.
>
> Well, this compiles but the admin only has access to his/her
> own x. So when i click on initializeButton, only the admin's
> instance of x changes. Is there a way to have ALL instances
> of x changing? Or user y's instance of x changing?
>
This is not the way to share data amongst a group of programs.
I'm assuming the administrator is using a client program, as are the other
users, to access the 'chat server'. Now, since the server is accessed by
all, *it* should be the location any client information the administrator
must access should be stored.
So, for example, the server might host an array, or 'ArrayList' [or similar]
of permanent user data, perhaps another of logged in user data [or the two
may be combined by not having all fields filled]. Of course, only the
administrator would be granted access to such data.
If this is not clear may I suggest reading up on client / server
applications. A useful tutorial might be:
http://java.sun.com/docs/books/tutorial/networking/index.html
as would:
http://java.sun.com/docs/books/tutorial/together/index.html
I hope this helps.
Anthony Borla
- Next message: Adam: "Re: Extended break"
- Previous message: Navigator: "Re: Can someone please tell me what this means?"
- In reply to: E-Wiz: "HELP! Updating a 'global' variable in a chat application"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|