码迷,mamicode.com
首页 > 编程语言 > 详细

java实现鼠标拖拽动作监听

时间:2015-04-07 12:06:31      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:鼠标拖动

技术分享



源代码

<span style="font-size:14px;">import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import java.awt.event.WindowListener ;
import java.awt.event.MouseMotionAdapter ;
import java.awt.event.MouseMotionListener ;
import java.awt.event.WindowAdapter ;
import java.awt.event.WindowEvent ;
import java.awt.event.KeyEvent ;
import java.awt.event.MouseEvent ;
import java.awt.event.MouseAdapter ;
import java.awt.event.KeyAdapter ;
import java.awt.event.KeyListener ;
import java.awt.event.MouseListener ;
import javax.swing.JTextArea ;
import javax.swing.JFrame ;
import javax.swing.JScrollPane ;
import javax.swing.JPasswordField ;

class MyMouse extends JFrame
{  
        //JTextArea text = new JTextArea() ;
        public MyMouse()
        {
            super.setTitle("鼠标精灵") ;
            super.addMouseMotionListener(new MouseMotionAdapter()
            {
                public void mouseDragged(MouseEvent e)
                {
                   System.out.println("x坐标:"+e.getX()+"  y坐标:"+e.getY()) ;
                }
            }) ;
            super.addWindowListener(new WindowAdapter()
           {
             public void WindowClosing(WindowEvent e)
            {
               System.exit(1) ;
            }
           }) ;
          
           super.setSize(400,300) ;
           super.setVisible(true) ;   
        }
       
   
} ;

class Tester
{
   public static void main(String args[])
   {
      MyMouse mhk = new MyMouse() ;
   }
} ;
</span>


java实现鼠标拖拽动作监听

标签:鼠标拖动

原文地址:http://blog.csdn.net/u012566693/article/details/44916569

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!