this is my codes after i modified the original codes.
it can be compiled but when i run nothing happens.
please help me..import java.lang.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class ChatApplet2 extends Applet implements ActionListener,Runnable
{
String user;
String msg;
String chatServer;
ObjectOutputStream output;
ObjectInputStream input;
Socket client;
public void init() {
super.init();
//{{INIT_CONTROLS
setLayout(new BorderLayout(0,0));
addNotify();
resize(518,347);
setBackground(new Color(12632256));
displayArea = new java.awt.TextArea("",2,0,TextArea.SCROLLBARS_NONE);
displayArea.setEditable(false);
displayArea.disable();
//displayArea.hide();
displayArea.reshape(0,0,380,216);
add(displayArea);
idbox = new java.awt.TextField();
idbox.reshape(84,288,284,24);
add(idbox);
button1 = new java.awt.Button("EnterRoom");
button1.reshape(384,288,72,21);
add(button1);
list = new java.awt.List();
//list.TOP_ALIGNMENT();
//list.disable();
list = new java.awt.List(5);
list.add("#Default User"+"\n");
list.reshape(384,24,128,196);
list.setFont(new Font("Helvetica", Font.BOLD, 12));
add(list);
label2 = new java.awt.Label("Members");
label2.reshape(396,0,100,19);
add(label2);
label1 = new java.awt.Label("UserName");
label1.reshape(0,288,72,27);
add(label1);
enterField = new java.awt.TextField();
enterField.reshape(84,240,431,44);
add(enterField);
label3 = new java.awt.Label("EnterText");
label3.reshape(0,252,72,25);
add(label3);
//}}
//uf = new UserFrame();
button1.addActionListener(this);
idbox.addActionListener(this);
enterField.addActionListener(this);
list.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==idbox)
{
user = idbox.getText()+"\n";
list.addItem(user.trim());
idbox.setText("");
displayArea.append(user +" HAS JOINED THE GROUP");
}
if(ae.getSource().equals(button1))
{
user = idbox.getText()+"\n";
list.addItem(user.trim());
idbox.setText("");
displayArea.append(user +" HAS JOINED THE GROUP");
}
if(ae.getSource().equals(enterField))
{
sendData(ae.getActionCommand() );
/*msg = enterField.getText();
displayArea.append(msg +"\n");
enterField.setText("");*/
}
if(ae.getSource().equals(list))
{
String l = list.getSelectedItem();
//uf.setTitle(l);
//Frame i[] = uf.getFrames();
//uf.setVisible(true);
}
}
public void start()
{
try {
// Step 1: Create a Socket to make connection
connectToServer();
// Step 2: Get the input and output streams
getStreams();
// Step 3: Process connection
processConnection();
// Step 4: Close connection
closeConnection();
}
// server closed connection
catch ( EOFException eofException ) {
System.out.println( "Server terminated connection" );
}
// process problems communicating with server
catch ( IOException ioException ) {
ioException.printStackTrace();
}
if(vt == null)
{
vt = new Thread(this,getClass().getName());
vt.start();
}
}
public void run()
{
try{
for(int i=0;i<10;i++)
{
displayArea.append("One stop Java source code -
www.globalleafs.com"+"\n"); displayArea.setForeground(Color.red);
vt.sleep(30000);
vt.resume();
}
}catch(Exception e){e.printStackTrace();}
}
private void sendData( String msg )
{
// send object to server
try {
output.writeObject( user + ">>> " + msg );
output.flush();
displayArea.append( "\nuser>>>" + msg );
}
// process problems sending object
catch ( IOException ioException ) {
displayArea.append( "\nError writing object" );
}
}
// get streams to send and receive data
private void getStreams() throws IOException
{
// set up output stream for objects
output = new ObjectOutputStream(
client.getOutputStream() );
// flush output buffer to send header information
output.flush();
// set up input stream for objects
input = new ObjectInputStream(
client.getInputStream() );
displayArea.append( "\nGot I/O streams\n" );
}
// connect to server
private void connectToServer() throws IOException
{
displayArea.setText( "Attempting connection\n" );
// create Socket to make connection to server
client = new Socket(
InetAddress.getByName( chatServer ), 5000 );
// display connection information
displayArea.append( "Connected to: " +
client.getInetAddress().getHostName() );
}
// process connection with server
private void processConnection() throws IOException
{
// enable enterField so client user can send messages
enterField.setEnabled( true );
// process messages sent from server
do {
// read message and display it
try {
msg = ( String ) input.readObject();
displayArea.append( "\n" + msg );
displayArea.setCaretPosition(
displayArea.getText().length() );
}
// catch problems reading from server
catch ( ClassNotFoundException classNotFoundException ) {
displayArea.append( "\nUnknown object type received" );
}
} while ( !msg.equals( "SERVER>>> TERMINATE" ) );
} // end method process connection
// close streams and socket
private void closeConnection() throws IOException
{
displayArea.append( "\nClosing connection" );
output.close();
input.close();
client.close();
}
java.awt.TextArea displayArea;
java.awt.TextField idbox;
java.awt.Button button1;
java.awt.List list;
java.awt.Label label2;
java.awt.Label label1;
java.awt.TextField enterField;
java.awt.Label label3;
private Thread vt;
}