![]() |
| ||
| Applet question.. I have the following code that produces an applet of two eyeballs. I have a mouseMotionListener that is set so that when the mouse is moved around the pair of eyes, the eyeballs follow the pointer. I have the eyeballs set up in four locations. To the left, right, north, and south in the eye. However, when I move the mouse onto the applet all four are displayed. Is there a simple way so that the correct set of eyes are displayed? Thank you in advance, here is my code.... package project5; |
| ||
| Re: Applet question.. You should only be setting mouseLeft, mouseRight, etc to true if, in fact, the mouse was moved in that sector. When your mouseMoved method gets called, you are setting ALL of them to true, then calling repaint. The way you're currently doing it, if mouseLeft were to be set true, it would always remain true, which is one problem. Also, currently, if mouseDown were true, it would call repaint. However, the mouseMoved method just set mouseUp, mouseDown, mouseLeft, and mouseRight ALL to true - so all of them will be repainted. hope that helps. |
| ||
| Re: Applet question.. To demonstrate the second point I made above, consider what happens when you move the mouse. Lets say you move the mouse down, but you do not move it in any other direction. The mouseMoved method is called, and mouseLeft is set to true. Now, lets say you eventually make it down to mouseDown = true. Then, repaint is called where you have if (Y > 250). Now, you enter the repaint method. Since mouseLeft is true, and mouseRight is true... both of those things will be repainted. Now, another thing will happen: since you never reset mouseLeft, mouseRight, mouseUp, and mouseDown to "false"... every time you enter the repaint method, these things might be repainted. Consider using "else if" statements inside of mouseMoved to call repaint, so that repaint is never called when you don't want it to be. Also, make sure that at the end of mouseMoved, you reset all of the mouseUp, down, left, and right variables to false. Also, do not set these variables to "true" until you have determined that they should be true. In other words, setting them to true should be done inside the if statement, not outside of it. Also, I'm not exactly sure how your assignment works, but you should consider that any time you color something, you are never un-coloring it. So lets say you color something because of mouseDown. What happens when the thing you colored isn't in the "mouseDown" sector anymore? Shouldn't you un-color it? Quote:
|
| All times are GMT -4. The time now is 11:09 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC