/*ch0711.java*/
import javax.swing.*;
import java.awt.*;
import java.awt.*;
public class Mouse extends JFrame implements MouseListener,MouseMotionListener
{ JPanel p1=new JPanel();
  JPanel p2=new JPanel();
  JTextArea area=new JTextArea(5,40);
  int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
  int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
  JScrollPane jsp=new JScrollPane(area,v,h);
  public Mouse()
  { super("鼠标移动事件例子");
    Container c=getContentPane();
    c.add("North",jsp);
    c.add("West",p1);
    c.add("East",p2);
    p1.add(new JLabel("这是第一个面板",JLabel.CENTER));
    p2.add(new JLabel("这是第二个面板",JLabel.CENTER));
    p1.setBackground(Color.blue);
    p1.addMouseListener(this);
    p1.addMouseMotionListener(this);
    p2.setBackground(Color.green);
    p2.addMouseListener(this);
    p2.addMouseMotionListener(this);
    addWindowListener(new Win());
    setSize(300,300);
    show();
  }
  public void mousePressed(MouseEvent e)
  { if(e.getSource()==p1)
      area.append("你在panell("+e.getX()+","+e.getY()+")按下鼠标\n");
    else
      area.append("你在panel2("+e.getX()+","+e.getY()+")按下鼠标\n");
  }

  public void mouseClicked(MouseEvent e)
  { if(e.getSource()==p1)
      area.append("你在panell("+e.getX()+","+e.getY()+")点击鼠标\n");
    else
      area.append("你在pane12("+e.getX()+","+e.getY()+")点击鼠标\n");
  }
  public void mouseEntered(MouseEvent e)
  { if(e.getSourece()==p1)
      area.append("鼠标进入Panell\n");
    else
      area.append("鼠标进入Panel2\n");
  }
  public void mouseExited(MouseEvent e)
  {  if(e.getSourece()==p1)
      area.append("鼠标退出Panell\n");
    else
      area.append("鼠标退出Panel2\n");
  }
  public void mouseReleased(MouseEvent e)
  { area.append("释放鼠标\n");
  }
  public void mouseDragged(MouseEvent e)
  { area.append("鼠标拖动("+"e.getX()"+","+e.getY()+")\n");
  }
  public void mouseMoved(MouseEvent e) {}
  public static void main(String args[])
  { new Mouse();
  }
}
class Win extends WindowAdapter
{ public void windowClosing(WindowEvent e)
  { System.exit(0);
  }
}
