Class Pinglet
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----Pinglet
- public class Pinglet
- extends Applet
Example Applet to demonstrate Java sockets.
Sends messages to the Java Demo Server on the host (port
number 6666), and displays the replies.
-
Pinglet()
-
-
action(Event, Object)
-
Called each time something happens on the user interface.
-
init()
-
Applet initialisation method.
-
start()
-
Called each time the browser displays the page.
-
stop()
-
Called each time the browser leaves the page.
Pinglet
public Pinglet()
init
public void init()
- Applet initialisation method. We create our user interface
which consists of a button and two text areas. We
make sure that neither text area can be edited by the
user, as they are for display only.
- Overrides:
- init in class Applet
start
public void start()
- Called each time the browser displays the page.
This is where we create our socket, and obtain the data streams
we need to talk through it. We make sure that our "ping" button
is only enabled if we succeed in setting up the socket.
- Overrides:
- start in class Applet
stop
public void stop()
- Called each time the browser leaves the page.
We disable our "ping" button and close down the socket.
- Overrides:
- stop in class Applet
action
public boolean action(Event event,
Object arg)
- Called each time something happens on the user interface.
We only deal with the "ping" button here. When this is pressed
we send a message through the socket to the server machine,
and read the reply. The sent and received messages are
displayed in our text areas.
- Parameters:
- event - Identifies what happened in the GUI
- arg - The GUI object that was affected
- Returns:
- always "true" (shows we handled the event)
- Overrides:
- action in class Component