Java Reference
In-Depth Information
logoutButton . addActionListener ( new
new ActionListener () {
public
public void
void actionPerformed ( ActionEvent e ) {
logout ();
loginButton . setEnabled ( true
true );
logoutButton . setEnabled ( false
false );
loginButton . requestFocus ();
}
});
p . add ( new
new Label ( "Message here:" ));
tf = new
new TextField ( 40 );
tf . addActionListener ( new
new ActionListener () {
public
public void
void actionPerformed ( ActionEvent e ) {
iif ( loggedIn ) {
pw . println ( ChatProtocol . CMD_BCAST + tf . getText ());
tf . setText ( "" );
}
}
});
p . add ( tf );
cp . add ( BorderLayout . SOUTH , p );
cp . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );
cp . pack ();
}
protected
protected String serverHost = "localhost" ;
/** LOG ME IN TO THE CHAT */
public
public void
void login () {
showStatus ( "In login!" );
iif ( loggedIn )
return
return ;
try
try {
sock = new
new Socket ( serverHost , port );
is = new
new BufferedReader ( new
new InputStreamReader ( sock . getInputStream ()));
pw = new
new PrintWriter ( sock . getOutputStream (), true
true );
showStatus ( "Got socket" );
// FAKE LOGIN FOR NOW - no password neede
pw . println ( ChatProtocol . CMD_LOGIN + userName );
loggedIn = true
true ;
} catch
catch ( IOException e ) {
Search WWH ::




Custom Search