FileDocCategorySizeDatePackage
TerribleFlicker.javaAPI DocExample926Wed Mar 26 01:23:32 GMT 1997None

TerribleFlicker.java

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

public class TerribleFlicker extends java.applet.Applet 
									implements MouseMotionListener { 
	int grid = 10;
	int currentX, currentY;
	Image img;
	int imgWidth = 60, imgHeight = 60;

	public void init() {
		img = getImage( getClass().getResource(getParameter("img")) );
		addMouseMotionListener( this );
	}

	public void mouseDragged( MouseEvent e ) {
		currentX = e.getX(); currentY = e.getY();
		repaint();
	}
	public void mouseMoved( MouseEvent e ) { }; // complete MouseMotionListener

	public void paint( Graphics g ) {
		int w = getSize().width/grid;
		int h = getSize().height/grid;
		boolean black = false;
		for ( int y = 0; y <= grid; y++ ) 
			for ( int x = 0; x <= grid; x++ ) {
				g.setColor(  (black = !black) ? Color.black : Color.white );
				g.fillRect( x * w, y * h, w, h );
			}
		g.drawImage( img, currentX, currentY, imgWidth, imgHeight, this );
	}
}