java 为什么鼠标移动时mouseDragged没有调用
节选了部分程序,mainPaint显示后mouseDragged和mouseMoved都没反应,mousePressed等都有反应classMyFrameextendsF...
节选了部分程序,mainPaint显示后mouseDragged和mouseMoved都没反应,mousePressed等都有反应
class MyFrame extends Frame
{
MyDrawPanel mainPaint = new MyDrawPanel(this);
MyFrame()
{
mainPaint.addMouseListener(new MouseAdpt(this));
}
}
class MyDrawPanel extends Panel
{
MyFrame mainFrame;
MyDrawPanel(MyFrame mf)
{
mainFrame = mf;
}
}
class MouseAdpt extends MouseAdapter
{
MyFrame mainFrame;
public MouseAdpt(MyFrame mf)
{
mainFrame = mf;
}
public void mouseDragged(MouseEvent e)
{
System.out.println("mouseDragged");
}
} 展开
class MyFrame extends Frame
{
MyDrawPanel mainPaint = new MyDrawPanel(this);
MyFrame()
{
mainPaint.addMouseListener(new MouseAdpt(this));
}
}
class MyDrawPanel extends Panel
{
MyFrame mainFrame;
MyDrawPanel(MyFrame mf)
{
mainFrame = mf;
}
}
class MouseAdpt extends MouseAdapter
{
MyFrame mainFrame;
public MouseAdpt(MyFrame mf)
{
mainFrame = mf;
}
public void mouseDragged(MouseEvent e)
{
System.out.println("mouseDragged");
}
} 展开
展开全部
mouseDragged 顾名思义是“拖动”鼠标的意思。你得按住鼠标拖动才会调用啊。
mouseMoved 才是鼠标移动时会调用的。
------------------------------------------------------------------------
你忘写 addMouseMotionListener(new MouseAdapter()) 了哈!
不过你最好建一个 MouseAdapter 对象:
MouseAdapter ma = new MouseAdapter();
addMouseListener(ma);
addMouseMotionListener(ma);
mouseMoved 才是鼠标移动时会调用的。
------------------------------------------------------------------------
你忘写 addMouseMotionListener(new MouseAdapter()) 了哈!
不过你最好建一个 MouseAdapter 对象:
MouseAdapter ma = new MouseAdapter();
addMouseListener(ma);
addMouseMotionListener(ma);
展开全部
鼠标拖动 mouseDragged 选定并按住移动叫拖动
鼠标移动 mouseMoved 未选定对象的移动
鼠标移动 mouseMoved 未选定对象的移动
参考资料: www.asixer.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询