f



Dynamic updation of a JTextArea

I created a multi user chat system using sockets in java . everything works=
 perfect but a little issue. the common jtextarea where i am supposed to di=
splay the chats ( its a app wherein all the users write messages and the me=
ssage of all the users is visible in their chat space. Unfortunately the jt=
extarea is not updating itself whenever a client writes a message . I tried=
 doing like System.out.print(contents of the common textarea) . In the comm=
and prompt every single message written is displayed , which means the code=
 is working as intended . its just the textarea is not updating itself. i s=
earched many forums even tried doing the update thing in a different thread=
 than EDT but still i have the same problem. Can anyone help me out ? Here =
is the code .
=20
     public void run()
       {
            try
                 {
                      DataInputStream in =3D new DataInputStream(client.get=
InputStream());    //client is the socket object
                      clientName =3D in.readUTF();                         =
                                             //clientname is a string which=
 stores the name of the clients
=20
                      s =3D "Joined";
                      SwingUtilities.invokeLater(new Runnable(){
                      public void run()
                      {
                           clientChat.ta.append(clientName+": "+s);        =
 //clientchat is the name of the Client class and ta is the common textarea=
 object which is declared as a static variable
                      }
                      });
=20
                      while(!s.equals("terminate"))
                      {
                           s=3Din.readUTF();
                           SwingUtilities.invokeLater(new Runnable(){
                           public void run()
                           {
                                clientChat.ta.append(clientName+": "+s);
                            }
                           });
                      }
=20
            }catch(Exception e){e.printStackTrace();}
     }
=20
     every time a new client joins a new thread is created that acts as a s=
erver for the client. this is the class where the updation of the textarea =
is taking place. any help would be greatly praised.
0
abhprk3926
12/14/2016 2:16:31 PM
comp.lang.java.gui 8286 articles. 0 followers. Post Follow

12 Replies
404 Views

Similar Articles

[PageSpeed] 17

On 12/14/2016 08:16, abhprk3926@gmail.com wrote:
> I created a multi user chat system using sockets in java . everything
> works perfect but a little issue. the common jtextarea where i am
> supposed to display the chats ( its a app wherein all the users write
> messages and the message of all the users is visible in their chat
> space. Unfortunately the jtextarea is not updating itself whenever a
> client writes a message . I tried doing like
> System.out.print(contents of the common textarea) . In the command
> prompt every single message written is displayed , which means the
> code is working as intended . its just the textarea is not updating
> itself. i searched many forums even tried doing the update thing in a
> different thread than EDT but still i have the same problem. Can
> anyone help me out ? Here is the code .
>
> public void run() { try { DataInputStream in = new
> DataInputStream(client.getInputStream());    //client is the socket
> object clientName = in.readUTF();
> //clientname is a string which stores the name of the clients
>
> s = "Joined"; SwingUtilities.invokeLater(new Runnable(){ public void
> run() { clientChat.ta.append(clientName+": "+s);         //clientchat
> is the name of the Client class and ta is the common textarea object
> which is declared as a static variable } });
>
> while(!s.equals("terminate")) { s=in.readUTF();
> SwingUtilities.invokeLater(new Runnable(){ public void run() {
> clientChat.ta.append(clientName+": "+s); } }); }
>
> }catch(Exception e){e.printStackTrace();} }
>
> every time a new client joins a new thread is created that acts as a
> server for the client. this is the class where the updation of the
> textarea is taking place. any help would be greatly praised.
>

I don't see anything obvious in your code but I'm only seeing a piece of
it.  I suggest you try making an SSCCE and duplicating your problem or
maybe it will help you discover an answer.  Oh and formatting your code 
a little more neatly would help too.  Post an SSCCE here if you can't 
get it to work.

-- 

Knute Johnson
0
Knute
12/14/2016 3:14:26 PM
here is the class that handles multiple chat clients....
class chatServerThread implements Runnable
{
	Socket client;
	Thread t;
	String clientName,s="";
	
	chatServerThread(Socket socket)
	{
		client=socket;
		t=new Thread(this,"newThread");
		t.start();
	}
	
	public void run()
	{
		try
		{
			DataInputStream in = new     DataInputStream(client.getInputStream());
			s="Joined";
			
			clientName=in.readUTF();
			clientChat.ta.append(clientName+" : "+s);	

			while(!s.equals("terminate"))
			{
				s=in.readUTF();
				clientChat.ta.append(clientName+" : "+s);
			}
			
		}catch(Exception e){e.printStackTrace();}	
	}

}

here are the action event listeners in the client's class....

send.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				new Thread(new Runnable(){
					public void run()
					{
						try
						{
							out.writeUTF(messaget.getText());
					
						}catch(Exception e){e.printStackTrace();}
					}
				}).start();
				
			}
		});
		
		terminate.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				
				new Thread(new Runnable(){
					public void run()
					{
						try
						{
							out.writeUTF("terminate");
							send.setEnabled(false);
							connect.setEnabled(true);
							namet.setEditable(true);
							ipt.setEditable(true);
							portt.setEditable(true);
							messaget.setEditable(false);
							client.close();
							
						}catch(Exception e){e.printStackTrace();}

					}
				}).start();
			}
		});
		
		connect.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				
				new Thread(new Runnable(){
					public void run()
					{
						if(namet.getText().length() == 0 || portt.getText().length() == 0 || ipt.getText().length() == 0)
						{
							Toolkit.getDefaultToolkit().beep();
							JOptionPane.showMessageDialog(f1,"Make Sure These Details Are Filled: \n1:Name\n2:Port Number Of Server\n3:Server's IP Address","Notice",JOptionPane.ERROR_MESSAGE);
						}
						else	
						{
							try
							{
								client = new Socket(ipt.getText(),Integer.parseInt(portt.getText()));
								out = new DataOutputStream(client.getOutputStream());
								out.writeUTF(namet.getText());
								connect.setEnabled(false);
								namet.setEditable(false);
								messaget.setEditable(true);
								ipt.setEditable(false);
								portt.setEditable(false);
								send.setEnabled(true);
									
							}catch(Exception e){e.printStackTrace();}
									
						}
					}
				}).start();
				
			}
		});
0
abhprk3926
12/14/2016 4:44:47 PM
clientChat.ta is the common textarea for appending the messages.
0
abhprk3926
12/14/2016 4:47:29 PM
On 12/14/2016 10:47, abhprk3926@gmail.com wrote:
> clientChat.ta is the common textarea for appending the messages.
>

It's not clear to me from the pieces of your code that I have seen how 
this actually is supposed to function.  But that is really irrelevant, 
what we need here is an SSCCE (see http://sscce.org).

What I have seen of your code though does have some problems.  It would 
be good if you could provide the version of Java that you are using and 
whether the text area you are writing to is a JTextArea, an AWT TextArea 
or a JavaFX TextArea, all have different requirements for threading issues.

-- 

Knute Johnson
0
Knute
12/14/2016 9:15:45 PM
On 12/14/2016 15:15, Knute Johnson wrote:
> On 12/14/2016 10:47, abhprk3926@gmail.com wrote:
>> clientChat.ta is the common textarea for appending the messages.
>>
>
> It's not clear to me from the pieces of your code that I have seen how
> this actually is supposed to function.  But that is really irrelevant,
> what we need here is an SSCCE (see http://sscce.org).
>
> What I have seen of your code though does have some problems.  It would
> be good if you could provide the version of Java that you are using and
> whether the text area you are writing to is a JTextArea, an AWT TextArea
> or a JavaFX TextArea, all have different requirements for threading issues.
>

Well you did say JTextArea in the subject.  So all of the calls in that 
last bit you sent where things are enabled and set editable, needs to be 
done on the EDT.

If you are using Java 8 you can simplify that code considerably. 
Instead of:

something.addActionListener(new ActionListener() {
     public void ActionPerformed(ActionEvent ae) {
         new Thread(new Runnable() {
             public void run() {

you can use:

something.addActionListener(ae -> {
     new Thread(() -> {

To run code on the EDT:

EventQueue.invokeLater(() -> {
     // this code is run on EDT
});

-- 

Knute Johnson
0
Knute
12/14/2016 9:46:32 PM
Knute i thank you for your interest in solving my issue. What my applicatio=
n does is i have created a class in which a loop continously listens for co=
nnection requests. Another one that i posted in my previous comment is the =
chatServerThread class that allocates a new thread to each request. And the=
n the last class is the client chat window. What i have done is that i have=
 created a common textarea in which all the users write their messages. And=
 i have included that JTextarea ( JSwing ) in all of the client chat window=
.. But that textarea is not updating ehen i write a message from any one of =
the clients window. If you order me i would post the entire code here. Plea=
se help me out .
0
abhprk3926
12/14/2016 10:09:40 PM
Knute i thank you for your interest in solving my issue. What my applicatio=
n does is i have created a class in which a loop continously listens for co=
nnection requests. Another one that i posted in my previous comment is the =
chatServerThread class that allocates a new thread to each request. And the=
n the last class is the client chat window. What i have done is that i have=
 created a common textarea in which all the users write their messages. And=
 i have included that JTextarea ( JSwing ) in all of the client chat window=
.. But that textarea is not updating ehen i write a message from any one of =
the clients window. If you order me i would post the entire code here. Plea=
se help me out .
0
abhprk3926
12/14/2016 10:09:42 PM
On 12/14/2016 16:09, abhprk3926@gmail.com wrote:
> Knute i thank you for your interest in solving my issue. What my
> application does is i have created a class in which a loop
> continously listens for connection requests. Another one that i
> posted in my previous comment is the chatServerThread class that
> allocates a new thread to each request. And then the last class is
> the client chat window. What i have done is that i have created a
> common textarea in which all the users write their messages. And i
> have included that JTextarea ( JSwing ) in all of the client chat
> window. But that textarea is not updating ehen i write a message from
> any one of the clients window. If you order me i would post the
> entire code here. Please help me out .
>

So how many times have you added this one JTextArea to a container?

-- 

Knute Johnson
0
Knute
12/14/2016 10:23:31 PM
On 12/14/2016 16:09, abhprk3926@gmail.com wrote:
> Knute i thank you for your interest in solving my issue. What my
> application does is i have created a class in which a loop
> continously listens for connection requests. Another one that i
> posted in my previous comment is the chatServerThread class that
> allocates a new thread to each request. And then the last class is
> the client chat window. What i have done is that i have created a
> common textarea in which all the users write their messages. And i
> have included that JTextarea ( JSwing ) in all of the client chat
> window. But that textarea is not updating ehen i write a message from
> any one of the clients window. If you order me i would post the
> entire code here. Please help me out .
>

So how many times have you added this one JTextArea to a container?

-- 

Knute Johnson
0
Knute
12/14/2016 10:24:01 PM
just one time when i have created the chat class. here lemme show. here is the full code . 

import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Toolkit;

class mainServer
{
	public static void main(String args[])
	{
		if(args.length!=1)
		{
			System.out.println("Port Number Required");
			System.exit(-1);
		}
		
		try(ServerSocket server = new ServerSocket(Integer.parseInt(args[0])))
		{
			while(true)
				new chatServerThread(server.accept());
			
		}catch(Exception e){e.printStackTrace();}
	}
}

class chatServerThread implements Runnable
{
	Socket client;
	Thread t;
	String clientName,s="";
	
	chatServerThread(Socket socket)
	{
		client=socket;
		t=new Thread(this,"newThread");
		t.start();
	}
	
	public void run()
	{
		try
		{
			DataInputStream in = new DataInputStream(client.getInputStream());
			s="Joined";
			
			clientName=in.readUTF();
			clientChat.ta.append(clientName+" : "+s);	
		
			new Thread(new Runnable(){
				public void run()
				{
					while(!s.equals("terminate"))
					{
						try
						{
							s=in.readUTF();
							clientChat.ta.append(clientName+" : "+s);
							
						}catch(Exception e){e.printStackTrace();}
						
					}
				}
			}).start();
			
			
		}catch(Exception e){e.printStackTrace();}	
	}

}

class clientChat
{
	public JFrame f1 = new JFrame();
	public JLabel name = new JLabel("Enter Name : ");
	public JTextField namet = new JTextField(20);
	public JLabel port = new JLabel("Enter Port Number : ");
	public JTextField portt = new JTextField(20);
	public JLabel ip = new JLabel("Enter Server's IP : ");
	public JTextField ipt = new JTextField(20);
	public JButton connect = new JButton("Connect To Server");
	public JLabel message = new JLabel("Write Message : ");
	public JTextField messaget = new JTextField(20);
	public static JTextArea ta = new JTextArea();
	public static JScrollPane jsp = new JScrollPane(ta);
	public JButton  send = new JButton("Send Message");
	public JButton terminate = new JButton("Close Session");
	Socket client=null;
	DataOutputStream out=null;
	
	clientChat()
	{
		f1.setSize(525,400);
		send.setEnabled(false);
		ta.setEditable(false);
		f1.setResizable(false);
		messaget.setEditable(false);
		f1.setTitle("Chat Window");
		f1.setLocationRelativeTo(null);
		f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout();
		f1.setVisible(true);
		
		send.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				
						try
						{
							out.writeUTF(messaget.getText());
					
						}catch(Exception e){e.printStackTrace();}
					
			}
		});
		
		terminate.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				
						try
						{
							out.writeUTF("terminate");
							send.setEnabled(false);
							connect.setEnabled(true);
							namet.setEditable(true);
							ipt.setEditable(true);
							portt.setEditable(true);
							messaget.setEditable(false);
							client.close();
							
						}catch(Exception e){e.printStackTrace();}

			}
		});
		
		connect.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{
				
				
						if(namet.getText().length() == 0 || portt.getText().length() == 0 || ipt.getText().length() == 0)
						{
							Toolkit.getDefaultToolkit().beep();
							JOptionPane.showMessageDialog(f1,"Make Sure These Details Are Filled: \n1:Name\n2:Port Number Of Server\n3:Server's IP Address","Notice",JOptionPane.ERROR_MESSAGE);
						}
						else	
						{
							try
							{
								client = new Socket(ipt.getText(),Integer.parseInt(portt.getText()));
								out = new DataOutputStream(client.getOutputStream());
								out.writeUTF(namet.getText());
								connect.setEnabled(false);
								namet.setEditable(false);
								messaget.setEditable(true);
								ipt.setEditable(false);
								portt.setEditable(false);
								send.setEnabled(true);
									
							}catch(Exception e){e.printStackTrace();}
									
						}
					
			}
		});
	}
	
	public void setLayout()
	{
		GroupLayout gl = new GroupLayout(f1.getContentPane());
		f1.getContentPane().setLayout(gl);
		gl.setAutoCreateGaps(true);
		gl.setAutoCreateContainerGaps(true);
		
		gl.setHorizontalGroup(
			gl.createParallelGroup()
				.addGroup(gl.createSequentialGroup()
					.addComponent(name)
					.addComponent(namet)
					.addComponent(connect))
				.addGroup(gl.createSequentialGroup()
					.addComponent(port)
					.addComponent(portt))
				.addGroup(gl.createSequentialGroup()
					.addComponent(ip)
					.addComponent(ipt))
				.addGroup(gl.createSequentialGroup()
					.addComponent(message)
					.addComponent(messaget)
					.addComponent(send))
				.addComponent(jsp)
				.addComponent(terminate)
		);
		
		gl.setVerticalGroup(
			gl.createSequentialGroup()
				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
					.addComponent(name)
					.addComponent(namet)
					.addComponent(connect))
				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
					.addComponent(port)
					.addComponent(portt))
				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
					.addComponent(ip)
					.addComponent(ipt))
				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
					.addComponent(message)
					.addComponent(messaget)
					.addComponent(send))
				.addComponent(jsp)
				.addComponent(terminate)
		);
		
		gl.linkSize(SwingConstants.HORIZONTAL,name,port,ip,message);
		gl.linkSize(SwingConstants.HORIZONTAL,namet,portt,ipt,messaget);
		gl.linkSize(SwingConstants.HORIZONTAL,connect,send);
	}

	public static void main(String args[])
	{
		SwingUtilities.invokeLater(new Runnable(){
			public void run()
			{
				new clientChat();
			}
		});
	}
	
}
0
abhprk3926
12/15/2016 8:18:49 AM
On 12/15/2016 02:18, abhprk3926@gmail.com wrote:
> just one time when i have created the chat class. here lemme show. here is the full code .
>
> import java.net.*;
> import java.io.*;
> import javax.swing.*;
> import java.awt.event.*;
> import java.awt.Toolkit;
>
> class mainServer
> {
> 	public static void main(String args[])
> 	{
> 		if(args.length!=1)
> 		{
> 			System.out.println("Port Number Required");
> 			System.exit(-1);
> 		}
> 		
> 		try(ServerSocket server = new ServerSocket(Integer.parseInt(args[0])))
> 		{
> 			while(true)
> 				new chatServerThread(server.accept());
> 			
> 		}catch(Exception e){e.printStackTrace();}
> 	}
> }
>
> class chatServerThread implements Runnable
> {
> 	Socket client;
> 	Thread t;
> 	String clientName,s="";
> 	
> 	chatServerThread(Socket socket)
> 	{
> 		client=socket;
> 		t=new Thread(this,"newThread");
> 		t.start();
> 	}
> 	
> 	public void run()
> 	{
> 		try
> 		{
> 			DataInputStream in = new DataInputStream(client.getInputStream());
> 			s="Joined";
> 			
> 			clientName=in.readUTF();
> 			clientChat.ta.append(clientName+" : "+s);	
> 		
> 			new Thread(new Runnable(){
> 				public void run()
> 				{
> 					while(!s.equals("terminate"))
> 					{
> 						try
> 						{
> 							s=in.readUTF();
> 							clientChat.ta.append(clientName+" : "+s);
> 							
> 						}catch(Exception e){e.printStackTrace();}
> 						
> 					}
> 				}
> 			}).start();
> 			
> 			
> 		}catch(Exception e){e.printStackTrace();}	
> 	}
>
> }
>
> class clientChat
> {
> 	public JFrame f1 = new JFrame();
> 	public JLabel name = new JLabel("Enter Name : ");
> 	public JTextField namet = new JTextField(20);
> 	public JLabel port = new JLabel("Enter Port Number : ");
> 	public JTextField portt = new JTextField(20);
> 	public JLabel ip = new JLabel("Enter Server's IP : ");
> 	public JTextField ipt = new JTextField(20);
> 	public JButton connect = new JButton("Connect To Server");
> 	public JLabel message = new JLabel("Write Message : ");
> 	public JTextField messaget = new JTextField(20);
> 	public static JTextArea ta = new JTextArea();
> 	public static JScrollPane jsp = new JScrollPane(ta);
> 	public JButton  send = new JButton("Send Message");
> 	public JButton terminate = new JButton("Close Session");
> 	Socket client=null;
> 	DataOutputStream out=null;
> 	
> 	clientChat()
> 	{
> 		f1.setSize(525,400);
> 		send.setEnabled(false);
> 		ta.setEditable(false);
> 		f1.setResizable(false);
> 		messaget.setEditable(false);
> 		f1.setTitle("Chat Window");
> 		f1.setLocationRelativeTo(null);
> 		f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> 		setLayout();
> 		f1.setVisible(true);
> 		
> 		send.addActionListener(new ActionListener(){
> 			public void actionPerformed(ActionEvent ae)
> 			{
> 				
> 						try
> 						{
> 							out.writeUTF(messaget.getText());
> 					
> 						}catch(Exception e){e.printStackTrace();}
> 					
> 			}
> 		});
> 		
> 		terminate.addActionListener(new ActionListener(){
> 			public void actionPerformed(ActionEvent ae)
> 			{
> 				
> 						try
> 						{
> 							out.writeUTF("terminate");
> 							send.setEnabled(false);
> 							connect.setEnabled(true);
> 							namet.setEditable(true);
> 							ipt.setEditable(true);
> 							portt.setEditable(true);
> 							messaget.setEditable(false);
> 							client.close();
> 							
> 						}catch(Exception e){e.printStackTrace();}
>
> 			}
> 		});
> 		
> 		connect.addActionListener(new ActionListener(){
> 			public void actionPerformed(ActionEvent ae)
> 			{
> 				
> 				
> 						if(namet.getText().length() == 0 || portt.getText().length() == 0 || ipt.getText().length() == 0)
> 						{
> 							Toolkit.getDefaultToolkit().beep();
> 							JOptionPane.showMessageDialog(f1,"Make Sure These Details Are Filled: \n1:Name\n2:Port Number Of Server\n3:Server's IP Address","Notice",JOptionPane.ERROR_MESSAGE);
> 						}
> 						else	
> 						{
> 							try
> 							{
> 								client = new Socket(ipt.getText(),Integer.parseInt(portt.getText()));
> 								out = new DataOutputStream(client.getOutputStream());
> 								out.writeUTF(namet.getText());
> 								connect.setEnabled(false);
> 								namet.setEditable(false);
> 								messaget.setEditable(true);
> 								ipt.setEditable(false);
> 								portt.setEditable(false);
> 								send.setEnabled(true);
> 									
> 							}catch(Exception e){e.printStackTrace();}
> 									
> 						}
> 					
> 			}
> 		});
> 	}
> 	
> 	public void setLayout()
> 	{
> 		GroupLayout gl = new GroupLayout(f1.getContentPane());
> 		f1.getContentPane().setLayout(gl);
> 		gl.setAutoCreateGaps(true);
> 		gl.setAutoCreateContainerGaps(true);
> 		
> 		gl.setHorizontalGroup(
> 			gl.createParallelGroup()
> 				.addGroup(gl.createSequentialGroup()
> 					.addComponent(name)
> 					.addComponent(namet)
> 					.addComponent(connect))
> 				.addGroup(gl.createSequentialGroup()
> 					.addComponent(port)
> 					.addComponent(portt))
> 				.addGroup(gl.createSequentialGroup()
> 					.addComponent(ip)
> 					.addComponent(ipt))
> 				.addGroup(gl.createSequentialGroup()
> 					.addComponent(message)
> 					.addComponent(messaget)
> 					.addComponent(send))
> 				.addComponent(jsp)
> 				.addComponent(terminate)
> 		);
> 		
> 		gl.setVerticalGroup(
> 			gl.createSequentialGroup()
> 				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
> 					.addComponent(name)
> 					.addComponent(namet)
> 					.addComponent(connect))
> 				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
> 					.addComponent(port)
> 					.addComponent(portt))
> 				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
> 					.addComponent(ip)
> 					.addComponent(ipt))
> 				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
> 					.addComponent(message)
> 					.addComponent(messaget)
> 					.addComponent(send))
> 				.addComponent(jsp)
> 				.addComponent(terminate)
> 		);
> 		
> 		gl.linkSize(SwingConstants.HORIZONTAL,name,port,ip,message);
> 		gl.linkSize(SwingConstants.HORIZONTAL,namet,portt,ipt,messaget);
> 		gl.linkSize(SwingConstants.HORIZONTAL,connect,send);
> 	}
>
> 	public static void main(String args[])
> 	{
> 		SwingUtilities.invokeLater(new Runnable(){
> 			public void run()
> 			{
> 				new clientChat();
> 			}
> 		});
> 	}
> 	
> }
>
I think I see what your problem is (or at least one of them).  In 
mainServer you reference clientChat.ta which is a static variable.  When 
mainServer then creates a clientChat object it is a different clientChat 
object than when the program clientChat creates that object.  You say 
"how can that be, it's static and there is only one static object?" 
Well there is one in the virtual machine that is running mainServer and 
there is one in the virtual machine that is running clientChat they 
aren't the same object.

I think this would have become obvious to you had you done as I 
suggested and created an SSCCE.  You would have seen that adding text to 
a JTextArea running in one virtual machine would not affect another 
JTextArea running in another virtual machine even if they are static.

In a classic "Chat" program you have clients connecting and 
disconnecting from the server and you have messages coming from a client 
to the server and back out to all the other clients.  Your server needs 
to be a little smarter and keep track of everybody that is connected so 
when a message comes in the server can send it out to everybody that is 
connected.


-- 

Knute Johnson
0
Knute
12/15/2016 8:58:21 PM
yes knute i think you are right. my approach is wrong. i need to make changes in my program. thanks very much for your solutions knute.
0
abhprk3926
12/16/2016 10:23:02 AM
Reply: