Java Reference
In-Depth Information
showStatus
(
"Can't get socket to "
+
serverHost
+
"/"
+
port
+
": "
+
e
);
cp
.
add
(
new
new
Label
(
"Can't get socket: "
+
e
));
return
return
;
}
// Construct and start the reader: from server to textarea.
// Make a Thread to avoid lockups.
new
new
Thread
(
new
new
Runnable
() {
public
public
void
void
run
() {
String line
;
try
try
{
while
while
(
loggedIn
&& ((
line
=
is
.
readLine
()) !=
null
null
))
ta
.
append
(
line
+
"\n"
);
}
catch
catch
(
IOException e
) {
showStatus
(
"Lost another client!\n"
+
e
);
return
return
;
}
}
}).
start
();
}
/** Log me out, Scotty, there's no intelligent life here! */
public
public
void
void
logout
() {
iif
(!
loggedIn
)
return
return
;
loggedIn
=
false
false
;
try
try
{
iif
(
sock
!=
null
null
)
sock
.
close
();
}
catch
catch
(
IOException ign
) {
// so what?
}
}
public
public
void
void
showStatus
(
String message
) {
System
.
out
.
println
(
message
);
}
/** A main method to allow the client to be run as an Application */
public
public static
void
main
(
String
[]
args
) {
ChatClient room101
=
new
static
void
new
ChatClient
();
room101
.
pack
();
room101
.
setVisible
(
true
true
);
}
}