鼠标监听求助
在做游戏的时候我用鼠标监听方法来去读取地图点击事件,但是无法和自己做的地图同步加载不进地图,自动生成的监听方法不能通过函数直接调用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("鼠标移动");
}