thanx a mill - sorted out now!
Now having a problem with my applet server - keeps on giving a runtime error: due (I think!)to the following line:
clientList = new JList();
in the AppletServer() method.
Its driving me mad(PLEASE HELP!) - I swear I'm not stupid!
Heres my AppletServer code
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import javax.swing.*;
public class AppletServer extends Thread
{
protected final static int defaultPort = 1976;
protected int paramPort;
protected ServerSocket server;
protected ThreadGroup tg;
protected JList clientList; //ambiguous
protected Vector clientVector;
protected Watcher watcher;
public static void main (String [] args)
{
System.out.println("The Chat Server is running");
int port = -1;
boolean background = true;
if(args.length == 0)
{ new AppletServer();
}
else if (args.length == 1)
{
if(args[0].equals(" -f"))
{
background = false;
new AppletServer(background);
}
else
{ try
{
port = Integer.parseInt(args[0]);
new AppletServer(port, background);
}
catch(NumberFormatException e)
{
System.out.print("not a valid port number");
System.out.println("use and inteer over 1024");
System.out.println(e);
System.out.println();
System.out.print("Starting sever on "+ defaultPort);
new AppletServer();
}
}
}
else if ( (args.length == 2) && args[0] == "-f")
{
background = false;
try
{
port = Integer.parseInt(args[0]);
new AppletServer(port, background);
}
catch(NumberFormatException e)
{
System.out.print("not a valid port number");
System.out.println("use and intsert over 1024");
System.out.println(e);
System.out.println();
System.out.print("Starting sever on "+ defaultPort);
new AppletServer();
}
}
else
System.out.println("usage: java AppletServer [-f] [<port_#>]");
}
public AppletServer()
{
super(); //create thread
try
{
server = new ServerSocket(defaultPort);
}
catch(IOException e)
{
System.out.println("could not create ServerSocket");
System.out.println(e);
System.exit(1);
}
tg = new ThreadGroup("Connections");
clientList = new JList();
clientVector = new Vector();
watcher = new Watcher(this);
this.start();
}
public AppletServer(boolean background)
{
super(); //create thread
try
{
server = new ServerSocket(defaultPort);
}
catch(IOException e)
{
System.out.println("could not create ServerSocket");
System.out.println(e);
System.exit(1);
}
tg = new ThreadGroup("Connections");
clientList = new JList(); //ambiguous
clientVector = new Vector();
watcher = new Watcher(this);
this.start();
Frame f = new Frame("AppletServer Monitor");
f.add("Center", clientList);
f.setSize(400, 300);
f.show();
this.start();
}
public AppletServer(int port, boolean background)
{
super(); //create thread
try
{ server = new ServerSocket(port);
}
catch(IOException e)
{
System.out.println("could not create ServerSocket");
System.out.println(e);
System.exit(1);
}
tg = new ThreadGroup("Connections");
clientList = new JList(); //ambiguous
clientVector = new Vector();
watcher = new Watcher(this);
Frame f = new Frame("AppletServer Monitor");
f.add("Center", clientList);
f.setSize(400, 300);
f.show();
this.start();
}
public void run()
{ try
{ for(;
{
Socket client = server.accept();
ClientConnect cc = new ClientConnect(this, client, tg, watcher);
synchronized(clientVector)
{
clientVector.addElement(cc);
//clientList.add(cc.toString());
clientList = new JList(clientVector);
}
}
}
catch(IOException e)
{
System.out.println("error accepting connections");
System.out.println(e);
System.exit(1);
}
}
}