Graffiti.java
This is the syntax highlighted version of Graffiti.java
from 3.5 Inheritance of
Introduction to Computer Science by
Robert Sedgewick and Kevin Wayne.
/*************************************************************************
* Compilation: javac Graffiti.java
* Execution: java Graffiti
* Dependencies: InteractiveDraw.java DrawListener.java
*
*
*************************************************************************/
import java.awt.Color;
public class Graffiti implements DrawListener {
private int SIZE = 512; // window dimension
private InteractiveDraw d = new InteractiveDraw(SIZE, SIZE); // drawing object
private int N = 0; // number of circles drawn
public Graffiti() {
d.addListener(this);
d.clear(Color.lightGray);
d.show();
}
// we don't need these here, but they're part of the interface
public void mousePressed(double x, double y) { }
public void mouseReleased(double x, double y) { }
public void keyTyped(char c) { }
// draw a spot as the user drags the mouse
public void mouseDragged(double x, double y) {
d.go(x, y);
d.setColorHSB(N % 256, 255, 255); // colors of the spectrum
d.spot(25);
d.show();
N++;
}
// test client
public static void main(String args[]) {
Graffiti g = new Graffiti();
}
}
Last updated: Thu Jun 10 17:03:51 EDT 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.