Spring Semester 2002


Lecture Notes Twenty-Four: Applets, events, event handling.

Today in class I would like to discuss this code:

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

public class Game extends Applet {
    int i = 0; 
    public void paint(Graphics g) {
        this.i = this.i + 1; 
        System.out.println("Paint called: " + i); 
    }
    public void init() {
        Umpire ump = new Umpire(); 
        this.addMouseMotionListener(ump); 
    }
} 

class Umpire implements MouseMotionListener { // wearing the uniform... 
    public void mouseDragged(MouseEvent e) {
        System.out.println("Ha! You're dragging the mouse."); 
    } 
    public void mouseMoved(MouseEvent e) {
        System.out.print  ( "Mouse seen being moved at: ("); 
        System.out.println( e.getX() + ", " + e.getY() + ")"); 
    } 
} 
This goes with the following HTML file:

<html>

  <head>
    <title>Game Applet One</title>
  </head>

  <body bgcolor=white>
    <applet code="Game.class" width=300 height=300>
    </applet>
  </body>

</html>
We'd like to understand this code very well.

We will also discuss Lab Ten, Vectors, interfaces.


Last updated: Apr 4, 2002 by Adrian German for A201