我在程序中遇到了鼠标事件问题。我试图用画布编写一个绘图程序。如何在Java中按下鼠标按钮时收听鼠标移动事件
如果用户左键单击并移动鼠标,应绘制图形。所以我在其中定义了Drawer
类,其中boolean allow_draw
,并且我添加了一个方法draw
。
draw
被称为在画布mousemoved
事件和allow_draw
设置真假与mousepressed
和released
。
然而,mousemoved
不点火,而我按下鼠标按钮...
我的问题是:我怎么能听鼠标动作,同时按下鼠标键。
希望你知道我在找什么:)
我不清楚为什么您需要'allow_draw'标志,但请注意,请确保您正确同步allow_draw。否则,您将遇到该变量货币的问题。 – RWVan3
谢谢,现在它工作! :) 我写在我的主要和设计器类的构造函数 ' public CanvasTest(){ initComponents(); this.drw =新的抽屉(this); this.canvas.addMouseMotionListener(new MouseMotionListener(this)); this.canvas.addMouseListener(new MouseClickListener(this)); //this.canvas.addMouseMotionListener(new MouseMotion(this)); } ' – user1795687
抱歉,codehighlighting不会对我工作...但我做你:) – user1795687