I recently worked on a 2d game in java, and I'm currently trying to get the event processing system to work correctly. I tried to click the mouse to start the animation, and it worked until I tried to move the mouse by clicking. Nothing is happening at the moment. I use the mouselistener and mousemotionlistener classes and the problem still persists. Here is the code from Main:
public class ML extends MouseAdapter{ public void mouseClicked(MouseEvent m){ if(m.getButton()==MouseEvent.BUTTON1) guns.playOnce(); } public void mouseReleased(MouseEvent m){ if(m.getButton()==MouseEvent.BUTTON1); }
It calls an animator class to simultaneously play back a set of images and stop. The animator worked fine before I turned on the mouse events. I cannot understand why it will not work during the movement of the mouse if no action is indicated during this movement of the mouse. (If there is an obvious solution, I'm sorry, I started Java not so long ago.)
java swing actionlistener mouseevent
Ryan
source share