Source:
/*
Trying to create a chatroom in java
Grrr...Property of Kit.
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class chat extends Applet implements ActionListener
{
TextArea msg=new TextArea(null,1,60,0);
TextArea ppl=new TextArea(null,15,20,0);
TextArea dsp=new TextArea(null,15,75,3);
TextField nameField=new TextField(10);
Label nspc=new Label(" ");
Label sspc=new Label(" ");
String name="Chatter";
int chatnum=1;
Button send=new Button("Send");
Button changeName=new Button("Change Name");
public void init()
{
add(dsp);
dsp.setEditable(false);
add(ppl);
ppl.setEditable(false);
ppl.setText("~People In Chat~");
add(nameField);
nameField.setText(name);
add(nspc);
add(changeName);
changeName.addActionListener(this);
add(msg);
add(sspc);
add(send);
send.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==send)
{
dsp.setText(dsp.getText()+name+": "+msg.getText()+"\n");
msg.setText("");
return;
}
if(e.getSource()==changeName)
{
dsp.setText(dsp.getText()+name+" changes thier name to: "+nameField.getText()+"\n");
name=nameField.getText();
nameField.setText(name);
return;
}
}
}