package experiment3;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class ChatClient extends Frame
{
/**
*
*/
private static final long serialVersionUID = -4869686737081404264L;
TextArea ta = new TextArea();
TextField tf = new TextField();
public void launchFrame() throws Exception
{
this.add(ta, BorderLayout.CENTER);
this.add(tf, BorderLayout.SOUTH);
tf.addActionListener(
new ActionListener()
{
public void actionPerformed(final ActionEvent ae)
{
try {
final String sSend = tf.getText();
if(sSend.trim().length() == 0) return;
ChatClient.this.send(sSend);
tf.setText("");
ta.append(sSend + "\n");
}
catch (final Exception e) { e.printStackTrace(); }
}
}
);
this.addWindowListener(
new WindowAdapter()
{
public void windowClosing(final WindowEvent e)
{
System.exit(0);
}
}
);
setBounds(300,300,300,400);
setVisible(true);
tf.requestFocus();
}
Socket s = null;
public ChatClient() throws Exception
{
s = new Socket("127.0.0.1", 8888);
launchFrame();
(new Thread(new ReceiveThread())).start();
}
public void send(final String str) throws Exception