Make your own free website on Tripod.com
 
   

, .

ClickMe . .

ClickMe . . . , , . .

: ClickMe.java Spot.java. html :


<applet code="ClickMe.class" width="300" height="150">
</applet>

. .

ClickMe

. : .

HTML . . ClickMe .

ClickMe . . ; .

. (, , ) , .

ClickMe

Spot . : size , , :

public class Spot {
    //instance variables
    public int size;
    public int x, y;

    //constructor
    public Spot(int intSize) {
        size = intSize;
        x = -1;
        y = -1;
    }
}

, -- -- . . . size . 1 .

. .

private Spot spot = null;
private static final int RADIUS = 7;
...
spot = new Spot(RADIUS);

Spot spot null . 7 RADIUS . ; new . Spot(RADIUS) RADIUS- . 7 .

ClickMe

, - :

  1. ()
  2. ()
  3. ()

ClickMe :

g.setColor(Color.white);

g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);

g Graphics . . , .

:

ClickMe

. Java Applet .

ClickMe ClickMe :

public class ClickMe extends Applet implements MouseListener {

...

}

ClickMe extends Applet Applet- . ClickMe , , , . ClickMe : paint , init .

public void init() {
    ... // ClickMe'   
}

public void paint(Graphics g) {
    ... // ClickMe'   
}

ClickMe

ClickMe . Java MouseListener . .

MouseListener , . . .

ClickMe . .

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

public class ClickMe extends Applet implements MouseListener {
    private Spot spot = null;
    private static final int RADIUS = 7;

    public void init() {
        addMouseListener(this);
    }

    public void paint(Graphics g) 
   {
        // draw a black border and a white background
        g.setColor(Color.white);
        g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);
        g.setColor(Color.black);
        g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);

        // draw the spot
        g.setColor(Color.red);
        if (spot != null) 
       {
            g.fillOval(spot.x - RADIUS,
                       spot.y - RADIUS,
                       RADIUS * 2, RADIUS * 2);
        }
    }
   
    public void mousePressed(MouseEvent event) 
   {
        if (spot == null) 
       {
            spot = new Spot(RADIUS);
        }
        spot.x = event.getX();
        spot.y = event.getY();
        repaint();
    }

    public void mouseClicked(MouseEvent event) {}
    public void mouseReleased(MouseEvent event) {}
    public void mouseEntered(MouseEvent event) {}
    public void mouseExited(MouseEvent event) {}
}

API

ClickMe . ClickMe Applet . ? Java API .

Java 2 API java.sun.com .

ClickMe Java API :

. :

[] [] []