Download the JDK
Search the Tutorials
Hide the TOC
Trail: Deployment
Lesson: Applets
Section: Practical Considerations When Writing Applets
Subsection: Working with a Server-Side Application
Applets
Getting Started with Applets
Importing Classes and Packages for Applets
Defining an Applet Subclass
The Life Cycle of an Applet
Methods for Milestones
Methods for Drawing and Event Handling
Methods for Adding UI Components
What Applets Can and Can't Do
Taking Advantage of the Applet API
Finding and Loading Data Files
Displaying Short Status Strings
Displaying Documents in the Browser
Sending Messages to Other Applets
Playing Sounds
Defining and Using Applet Parameters
Deciding Which Parameters to Support
Writing the Code to Support Parameters
Giving Information about Parameters
Using the APPLET Tag
Practical Considerations When Writing Applets
Security Restrictions
Creating a User Interface
Creating a GUI
Displaying Diagnostics to the Standard Output and Error Streams
Getting System Properties
Threads in Applets
Threads in Applets: Examples
Working with a Server-Side Application
A Simple Network Client Applet
Using a Server to Work Around Security Restrictions
Finishing an Applet
Before You Ship that Applet
The Perfectly Finished Applet
Deploying Applets
General Deployment Considerations
Using the applet Tag
Using the object Tag
Using the embed Tag
Deploying Applets in a Mixed-Browser Environment
Solving Common Applet Problems
Questions and Exercises
Home Page > Deployment > Applets
« Previous • Trail • Next »
A Simple Network Client Applet

> This section talks about the client to be an applet. Here's the `applet source code`. The client has been written not only to communicate with the host the applet came from, but also to have a graphical UI, and to have a loop so that it can get as many quotes as you like. You can run the applet by including it in a page with the following HTML code:

> >     <APPLET CODE=QuoteClientApplet.class WIDTH=500 HEIGHT=100>
> >     </APPLET>

> Here's a link to a `page` that contains the above HTML code. By saving this page to a file on your local HTTP server, you can use it to communicate with the server-side application that will be running on the HTTP server. You must also save the compiled form of the applet to the same directory.

> Before the applet can get quotes, you need to run the server on the host that the applet came from. You then need to note the number of the port that the server is listening on. After you enter this port number into the applet, it will hook up with the server and you'll be able to get one-line quotations. Below are detailed instructions, followed by pictures of the server and the applet in action.

> 1. Compile `QuoteServer.java` and `QuoteServerThread.java`. Here's a text file ( `one-liners.txt`) that should be in the same directory as the resulting class files.
> 2. On the computer that serves the applet class file (through HTTP), invoke the interpreter on the `QuoteServer` class. For example, if you view the applet's page with the URL http://mymachine/quoteApplet.html, then you need to run the server on the host named mymachine.
> 3. Record the port number that the quote server displays.
> 4. Enter this number into the applet's text field.
> 5. Press the Send button to request a quote from the server. You should see a quote appear in the text area.
> Here's a picture of the applet in action:

> QuoteServer sample output

« Previous • Trail • Next »
Previous page: Working with a Server-Side Application
Next page: Using a Server to Work Around Security Restrictions