// File: Blob1.java
// T Balls : March 1998
// Paint filled ovals on screen
// in response to mouse events
import java.awt.*;
import java.awt.event.*;
public class Blob1 extends Frame
{ public static void main( String[] args )
{ new Blob1();
}
public Blob1()
{ setTitle( "Blob1" );
setSize( 300, 300 );
addMouseListener( new MouseAdapter() {
public void mousePressed( MouseEvent e )
{ x = e.getX();
y = e.getY();
repaint();
}
});
addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e )
{ System.exit(0);
}
});
setVisible( true );
}
private int x = -50;
private int y = -50;
public void paint( Graphics g )
{ g.fillOval( x, y, 10, 10 );
}
public void update( Graphics g )
{ paint( g );
}
} |