Applets in the WWW:

  1. What is an applet:

    Applet is compiled Java program that is downloaded from a Web Server and runned on YOUR computer.

  2. Applet can potentially be a huge security problem (like viruses)...

  3. Why use Applet:

  4. How to put an Applet on a web page:

    Applet written in Java Version 1:
           WIDTH="400" HEIGHT="300">  

    Applet written in Java Version 2:
           WIDTH="400" HEIGHT="300">  

    The result:

    The CODE tag specifies the Java applet program that will be downloaded and run in browser

  5. The source of the applet program is:

    public class RectangleApplet extends Applet { public void paint(Graphics g) { // recover Graphics2D Graphics2D g2 = (Graphics2D)g; *************************** * Actual drawing command: * *************************** // Pick drawing color g2.setColor(; // construct a rectangle and draw it Rectangle cerealBox = new Rectangle(5, 10, 20, 30); g2.draw(cerealBox); // move rectangle 15 units sideways and 25 units down cerealBox.translate(15, 25); // draw moved rectangle g2.setColor(; g2.fill(cerealBox); } }

    Where is main() ??? ...Details on what the applet is doing will be discussed later...