// Figure 12.17:  MouseTracker.java
// D&D's application turned into an applet
// Demos mouse events
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MouseTracker extends JApplet implements MouseListener, MouseMotionListener {
	private Container c;
	private JLabel status;
	private JButton b;

	public void init( ) {
		c = getContentPane( );
		c.setLayout( new FlowLayout( ) );
		status = new JLabel( );	// no argument JLabel constructor
		c.add( status );
		b = new JButton( "Do Nothing" );
		b.addMouseListener( this );
		c.add( b );

		// applies to the entire applet window and not just a button
		addMouseListener( this );
		addMouseMotionListener( this );
	}

	// MouseEvent event handlers
	public void mouseClicked( MouseEvent e ) {
		status.setText( "Clicked at [ " + e.getX( ) + ", " + e.getY( ) + " ]" );
	}

	public void mousePressed( MouseEvent e ) {
		status.setText( "Pressed at [ " + e.getX( ) + ", " + e.getY( ) + " ]" );
	}

	public void mouseReleased( MouseEvent e ) {
		status.setText( "Released at [ " + e.getX( ) + ", " + e.getY( ) + " ]" );
	}

	public void mouseEntered( MouseEvent e ) {
		status.setText( "Mouse on button?" );
	}

	public void mouseExited( MouseEvent e ) {
		status.setText( "Mouse leaves button" );
	}

	// MouseMotionListener handlers
	public void mouseDragged( MouseEvent e ) {
		status.setText( "Dragged at [ " + e.getX( ) + ", " + e.getY( ) + " ]" );
	}

	public void mouseMoved( MouseEvent e ) {
		status.setText( "Moved at [ " + e.getX( ) + ", " + e.getY( ) + " ]" );
	}
}