Java Reference
In-Depth Information
fStatusLabel.setForeground (Color.BLUE);
}
else
{
Println ("* NOT CONNECTED *");
fStatusLabel.setText ("Disconnected");
fStatusLabel.setForeground (Color.RED);
}
}
catch (IOException e) {
println ("* NOT CONNECTED *");
fStatusLabel.setText ("Disconnected");
fStatusLabel.setForeground (Color.RED);
}
} // start
/**
* Connects to the server via a socket. Throws
* IOException if socket connection fails.
**/
boolean connect () throws IOException
{
println (
"
Attempting to connect to server...
"
);
try
{
// Connect to the server using the host IP address
// and the port at the server location
fServer
=
new Socket (fHost, fDataServerPort);
}
catch (SecurityException se) {
println ("Security Exception:
\
n"+se);
return false;
}
println ("Server connected - create worker");
// Create the worker to tend to this server
fDataClientWorker =
new DataClientWorker (this, fServer, fUserName);
fDataClientWorker.start ();
return true;
} // connect
/** Stop the worker thread. **/
public void stop ()
{
// Disconnect and kill the fDataClientWorker thread
fDataClientWorker.finish ();
setDisconnected ();
}
// stop
Search WWH ::
Custom Search