zoukankan      html  css  js  c++  java
  • java实现鼠标拖拽动作监听



    源代码

    <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>


  • 相关阅读:
    我的python中级班学习之路(全程笔记第一模块) (第一章)语言基础
    Python_常用模块
    Python_装饰器、迭代器、生成器
    Python_函数
    Python_深浅拷贝
    Python_文件操作
    Python_三级目录
    Python_循环判断表达式
    Python_基础语法
    7段数码管绘制
  • 原文地址:https://www.cnblogs.com/emoji/p/4436810.html
Copyright © 2011-2022 走看看