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

import javax.swing.*;

public class gui extends JFrame{
	private JPanel mousepanel;
	private JLabel statusbar;
	
	public gui(){
		super("Mouse Events");
		
		mousepanel=new JPanel();
		mousepanel.setBackground(Color.WHITE);
		add(mousepanel, BorderLayout.CENTER);
		
		statusbar=new JLabel("default");
		statusbar.setHorizontalAlignment(SwingConstants.CENTER);
		add(statusbar,BorderLayout.SOUTH);
		
		hand handler = new hand();
		mousepanel.addMouseListener(handler);
		mousepanel.addMouseMotionListener(handler);
	}
	private class hand implements MouseListener, MouseMotionListener{
		public void mouseDragged(MouseEvent event) {
		statusbar.setText(String.format("You are dragging at %d,  %d",event.getX(),event.getY()));
		}
		public void mouseMoved(MouseEvent event) {
			statusbar.setText(String.format("Moving %d,  %d",event.getX(),event.getY()));
		}
		public void mouseClicked(MouseEvent event) {
			statusbar.setText(String.format("Clicked at %d,  %d",event.getX(),event.getY()));
		}
		public void mouseEntered(MouseEvent event) {
			statusbar.setText("Welcome to area");
			mousepanel.setBackground(Color.BLUE);
		}
		public void mouseExited(MouseEvent event) {
			statusbar.setText("You Left the area");
			mousepanel.setBackground(Color.WHITE);
		}
		public void mousePressed(MouseEvent event) {
			statusbar.setText(String.format("Pressed at %d,  %d",event.getX(),event.getY()));
		}
		public void mouseReleased(MouseEvent event) {
			statusbar.setText(String.format("Released at %d,  %d",event.getX(),event.getY()));
		}
		
	}
}