Java Reference
In-Depth Information
/** BufferedReader for reading from socket */
protected
protected
BufferedReader is
;
/** PrintWriter for sending lines on socket */
protected
protected
PrintWriter pw
;
/** TextField for input */
protected
protected
TextField tf
;
/** TextArea to display conversations */
protected
protected
TextArea ta
;
/** The Login button */
protected
protected
Button loginButton
;
/** The LogOUT button */
protected
protected
Button logoutButton
;
/** The TitleBar title */
final
final static
static
String TITLE
=
"ChatClient: Ian Darwin's Toy Chat Room Client"
;
/** set up the GUI */
public
public
ChatClient
() {
cp
=
this
this
;
cp
.
setTitle
(
TITLE
);
cp
.
setLayout
(
new
new
BorderLayout
());
port
=
PORTNUM
;
// The GUI
ta
=
new
new
TextArea
(
14
,
80
);
ta
.
setEditable
(
false
false
);
// readonly
ta
.
setFont
(
new
new
Font
(
"Monospaced"
,
Font
.
PLAIN
,
11
));
cp
.
add
(
BorderLayout
.
NORTH
,
ta
);
Panel p
=
new
new
Panel
();
// The login button
p
.
add
(
loginButton
=
new
new
Button
(
"Login"
));
loginButton
.
setEnabled
(
true
true
);
loginButton
.
requestFocus
();
loginButton
.
addActionListener
(
new
new
ActionListener
() {
public
public
void
void
actionPerformed
(
ActionEvent e
) {
login
();
loginButton
.
setEnabled
(
false
false
);
logoutButton
.
setEnabled
(
true
true
);
tf
.
requestFocus
();
// set keyboard focus in right place!
}
});
// The logout button
p
.
add
(
logoutButton
=
new
new
Button
(
"Logout"
));
logoutButton
.
setEnabled
(
false
false
);