/*
 * file : MouseMotionDemo.java
 *
 * Mouse-motion events tell you when the user uses the mouse
 *(or a similar input device) to move the onscreen cursor.
 * When listening for other kinds of mouse events,
 * such as clicks, use a Mouse Listener.
 *
 * In this demo, the JPanel p2 and the JButton are
 * Mouse Motion Listeners
 *
 * No Window Listeners in this demo. Use ^C to exit
 */

import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import java.awt.Color;
import java.awt.BorderLayout;
import javax.swing.*;


public class MouseMotionDemo extends JFrame
                             implements MouseMotionListener {
	String newline;
	JPanel p1;
	JPanel p2;
	JPanel p3;
	JButton button;

	MouseMotionDemo() {
		super("Mouse Motion Demo");
		newline = System.getProperty("line.separator");
		p1 = new JPanel();
		p2 = new JPanel();
		//p2.setForeground(new Color(0,64,128));
		p2.setBackground(new Color(255,255,255));
		p3 = new JPanel();
		button = new JButton("Button");

		// button and panel 2 publish MouseMotionEvents
		p2.addMouseMotionListener(this);
		button.addMouseMotionListener(this);

		//add the buttons and labels to the panels
		p1.add(button);
		p2.add(new JLabel("Center"));
		p3.add(new JLabel("South"));

		// use BorderLayout on the content pane
		getContentPane().setLayout(new BorderLayout());

		// add the panels
		getContentPane().add(p1,BorderLayout.NORTH);
		getContentPane().add(p2,BorderLayout.CENTER);
		getContentPane().add(p3,BorderLayout.SOUTH);

		// make the JFrame Visible
		setSize(200,200);
		setVisible(true);
    	}// MouseMotionDemo

	public void mouseMoved(MouseEvent e) {
        	saySomething("Mouse moved;", e);
    	}

    	public void mouseDragged(MouseEvent e) {
       		saySomething("Mouse dragged;", e);
    	}

    	void saySomething(String eventDescription, MouseEvent e) {
		System.out.println(eventDescription + " detected on "
                        + e.getComponent().getClass().getName()
                        + newline);
    	}

	public static void main(String args[]) {
		new MouseMotionDemo();
	}

}//MouseMotionDemo
