标题:鼠标监听求助
只看楼主
mashunty
Rank: 1
等 级:新手上路
帖 子:4
专家分:9
注 册:2013-9-11
 问题点数:0 回复次数:0 
鼠标监听求助
在做游戏的时候我用鼠标监听方法来去读取地图点击事件,但是无法和自己做的地图同步加载不进地图,自动生成的监听方法不能通过函数直接调用ReadingMap 是我的地图的类,
例如:public void mouseDragged(MouseEvent e) {
        // TODO Auto-generated method stub
        String string = "鼠标拖动到位置:(" + e.getX() + "," + e.getY() +")";
    }
无法通过mouseDragged来去调用此函数;
public class Mouse implements MouseMotionListener,MouseListener {
     
    ReadingMap frame;        
    public Mouse(){                  
        frame.addMouseListener(this);  
        frame.addMouseMotionListener(this);  
        frame.addWindowListener(new WindowAdapter() {  
            @Override  
            public void windowClosing(WindowEvent e) {  
                // TODO Auto-generated method stub  
                System.exit(0);  
            }  
        });   
        frame.setVisible(true);  
    }
   
    public void mouseClicked(MouseEvent e ){
        // TODO Auto-generated method stub
         System.out.print("鼠标点击----" + "\t");  
            if (e.getClickCount()==1) {  
                System.out.println("单击!");  
            } else if (e.getClickCount()==2) {  
                System.out.println("双击!");  
            } else if (e.getClickCount()==3) {  
                System.out.println("三连击!!");  
            }  
    }

    @Override
    public void mouseEntered(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标");
    }

    @Override
    public void mouseExited(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标单击");
    }

    @Override
    public void mousePressed(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标按下");
    }

    @Override
    public void mouseReleased(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标放开");
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        // TODO Auto-generated method stub
        String string = "鼠标拖动到位置:(" + e.getX() + "," + e.getY() +")";
    }

    @Override
    public void mouseMoved(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标移动");
    }
搜索更多相关主题的帖子: public frame method 游戏 
2013-09-11 23:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-420462-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019044 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved