Lab Recap, Applets

Tom Kelliher, CS 116

Sept. 8, 2000

Administrivia

Announcements

The recurring concept of conceptual and formal models.

Assignment

Read Sections 2.1--2. Look through 2.8. This is the interface documentation for the Java-provided classes we're using.

From Last Time

Lab 1.

Outline

  1. Quiz 1.

  2. Lab recap.

  3. Applets: a closer look.

Coming Up

More on applets. Methods.

Recap of Lab

Observations:

  1. Purpose of the labs: Learn and apply. See the objectives.

    By now, you should be able to create a new Java project in JWS and add a file to it. Practice with Add.java, if necessary.

  2. For all restricted web site areas remember that the username and password will be what they were for the lab.

  3. The project folder contains an HTML file you can use to view the applet in a browser.

  4. Details matter:
    1. Why the quotes? ("Colors.java")

    2. Why not colors or Colours?

  5. How to deal with the ``blank'' applet:
    1. Close project files.

    2. Make another project current (highlighted in blue).

    3. Select the project you want to delete. Make sure it's not highlighted.

    4. Open the Project menu and delete it.

    5. Open the File menu, choose New and re-create the project. Make sure you only add the .java file!

  6. What's the smallest applet look like? How useful is it?

Applets

Recall our first example:

import java.applet.*;
import java.awt.*;

// The Hello class simply displays the string "Hello, world!"
// within the graphics object.

public class Hello extends Applet
{
   public void paint(Graphics g)
   {
      g.drawString("Hello, world!", 20, 10);
   }
}
Let's look at the applet in more detail:
  1. import statement: import java.applet.*;
    1. A class must be imported before it can be used.

    2. ; ends a statement. Required.

      Missing semicolons and compiler diagnostics.

    3. java.applet and java.awt are packages --- collections of classes. For example: java.applet.Applet and java.applet.AppletStub.

    4. The * is a wildcard --- match anything.

    5. Importing a package vs. a class. What class do we really need from java.awt?

  2. class declaration:
    public class Hello extends Applet
    {
       // ...
    }
    
    Meaning of each of the keywords/identifiers? Identifier-forming rules? Uniqueness. Conventions.



Thomas P. Kelliher
Thu Sep 7 12:53:45 EDT 2000
Tom Kelliher