FileDocCategorySizeDatePackage
ScribblePane1.javaAPI DocExample2381Sat Jan 24 10:44:32 GMT 2004je3.gui

ScribblePane1

public class ScribblePane1 extends JPanel implements MouseListener, MouseMotionListener
A simple JPanel subclass that uses event listeners to allow the user to scribble with the mouse. Note that scribbles are not saved or redrawn.

Fields Summary
protected int
last_x
protected int
last_y
Constructors Summary
public ScribblePane1()

	// This component registers itself as an event listener for
	// mouse events and mouse motion events.
	this.addMouseListener(this);
	this.addMouseMotionListener(this);

	// Give the component a preferred size
	setPreferredSize(new Dimension(450,200));
    
Methods Summary
public voidmouseClicked(java.awt.event.MouseEvent e)

public voidmouseDragged(java.awt.event.MouseEvent e)

	int x = e.getX();    // Get the current mouse position
	int y = e.getY();
	// Draw a line from the saved coordinates to the current position
	this.getGraphics().drawLine(last_x, last_y, x, y);
	last_x = x;          // Remember the current position
	last_y = y;
    
public voidmouseEntered(java.awt.event.MouseEvent e)

public voidmouseExited(java.awt.event.MouseEvent e)

public voidmouseMoved(java.awt.event.MouseEvent e)

public voidmousePressed(java.awt.event.MouseEvent e)

	last_x = e.getX();  // remember the coordinates of the click
	last_y = e.getY();
    
public voidmouseReleased(java.awt.event.MouseEvent e)