CHAPTER 3  An Introduction to Java Applets
TOC
 Setting Up A Java Applet EnvironmentTOC  
We wish to create an environment in 
which it will be easy to compile and run java applets.  
We begin by creating a file  in which to keep our work. 
In LINUX created a folder called "javaapplets and in that folder create a folder named
"Scrib" which will eventually contain a 
java program applet and any class files and HTML files necessary for the applet.  To run an appplet over the www it is necessary to create an HTML file which points to and contains the applet.
   
Now  download the files in the "Scrib" folder and put them in your own folder.  I like to keep different applets in different folders since they may have several external class elements.  When several applets are in the same folder it is easy to forget what the class elements belong to or to accidentally overwrite an old class element with an element in a different application.  You may  open a text editor and type or copy the file if you so desire.  Save the  file "Scrib.java," and the file "scrib.htm."
  
Now type in the file Scrib.java which you will 
find in the subdirectory. You can compile the java applet  at a command line by
typing 
   >$ javac filename.java
   or you may use the emacs editor and compile as before. To view the applet it is necessary to create a HTML file as we mentioned above.  Open the "scrib.htm" file using any editor.  It should look something like this:
  
< HTML> 
< HEAD> 
< TITLE>JAVA APPLET SCRIB<  
 
< /HEAD> 
 
< BODY  BGCOLOR="BBBBBB"  
              TEXT="000000"LINK="000044" VLINK="000044" ALINK="000044"> 
 
< APPLET CODE="Scrib.class" NAME="Scrib" WIDTH=500 HEIGHT=300> 
< /APPLET> 
 
 
< /Body> 
< /HTML> 
  
Once the applet has been compiled in the same folder as the HTML file  it may be viewed by the command
  
 >$ appletviewer scrib.htm
  Of course the path to the javac command must be set in the 
environment or else the entire path name must be used.  If you are using emacs then there is a menu command to view the applet.  This is currently set to use Netscape.  If you use this option then you must exit Netscape each time you edit and recompile the applet.  Ntesscape will only reload the HTML file and not the applet.  If you use the command line and the JAVA appletviewer, then you may reload the applet from the menu whenever you recompile.
  Once these steps have been completed it is only necessary 
to compile the applet 
using the  one of the methods outlined above..  We have discussed the java environment for the LINUX system, however the procedures in a Windows or Macintosh environment are similar.  Note that the examples given in the subdirectories are not compiled.  They must be compiled before they can be viewed.  You must compile them.
  Project 1  Now extend the scribble pad by adding additional colors (see for instance the Geom folder).
  Project 2  Extend by adding a button which will draw a square and a 
button which will draw a circle.
  
Project 3  Study the graphics drawing programs in the subdirectory Draw and 
write a program which draws a picture e.g. a house; a flower et cetera. 
  
Project 4  Study the cartoon and write an applet 
which moves a circle across the screen as an animation.  Now write an applet that rolls a wheel across the screen.
  
Project 5  Study the the applet in Cube and write a applet which rotates a square
when the mouse is dragged in the x direction.
  References TOC
 
 |