Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #5503

Re: Dynamic updation of a JTextArea

Newsgroups comp.lang.java.gui
Date 2016-12-14 08:44 -0800
References <0f003cf3-2058-4286-8669-a75fe3f116c3@googlegroups.com> <o2rnhu$sgf$1@dont-email.me>
Message-ID <c2b384b1-c28a-4c72-a742-543c638ef654@googlegroups.com> (permalink)
Subject Re: Dynamic updation of a JTextArea
From abhprk3926@gmail.com

Show all headers | View raw


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();
				
			}
		});

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Dynamic updation of a JTextArea abhprk3926@gmail.com - 2016-12-14 06:16 -0800
  Re: Dynamic updation of a JTextArea Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-12-14 09:14 -0600
    Re: Dynamic updation of a JTextArea abhprk3926@gmail.com - 2016-12-14 08:44 -0800
      Re: Dynamic updation of a JTextArea abhprk3926@gmail.com - 2016-12-14 08:47 -0800
        Re: Dynamic updation of a JTextArea Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-12-14 15:15 -0600
          Re: Dynamic updation of a JTextArea Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-12-14 15:46 -0600
            Re: Dynamic updation of a JTextArea abhprk3926@gmail.com - 2016-12-14 14:09 -0800
            Re: Dynamic updation of a JTextArea abhprk3926@gmail.com - 2016-12-14 14:09 -0800
              Re: Dynamic updation of a JTextArea Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-12-14 16:23 -0600
              Re: Dynamic updation of a JTextArea Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-12-14 16:24 -0600
                Re: Dynamic updation of a JTextArea abhprk3926@gmail.com - 2016-12-15 00:18 -0800
                Re: Dynamic updation of a JTextArea Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-12-15 14:58 -0600
                Re: Dynamic updation of a JTextArea abhprk3926@gmail.com - 2016-12-16 02:23 -0800

csiph-web