Java Reference
In-Depth Information
buffer.append("POSITION "
!
((Integer)event.value).intValue());
return
buffer;
}
}
package
jogging.client;
import
java.io.*;
import
java.net.*;
import
java.awt.*;
import
javax.swing.event.*;
import
javax.swing.*;
public class
JoggingApplet
extends
JApplet
implements
Runnable {
private
PathPanel pathPanel
#
new
PathPanel();
// the graphical panel
private
JSlider speedSlider
#
new
JSlider();
// the speed control button
private
BufferedReader input
#
null
;
// the socket input buffer
private
PrintWriter output
#
null
;
// the socket output buffer
public synchronized void
init() {
this
.getContentPane().add(pathPanel,
null
);
speedSlider.addChangeListener(
new
javax.swing.event.ChangeListener() {
public void
stateChanged(ChangeEvent e) {
output.println
("MSG: SPEED "
!
speedSlider.getValue());
output.flush();
}
});
this
.getContentPane().add(speedSlider,
null
);
// gets connected to the remote server and starts the
// thread
try
{
// reads the HOST address and the PORT number
// from the HTML file that embedds the applet
String host
#
getParameter("HOST");
int
port
#
Integer.parseInt( getParameter("PORT") );
// creates the socket and the input/output buffers
Socket socket
#
new
Socket(host, port);
input
#
new
BufferedReader(
new
InputStreamReader
(socket.getInputStream()));
output
#
new
PrintWriter
(socket.getOutputStream(),
false
);