I used this kind of enviroment for my hearts game. I used an applet which implements Runnable only, just for using threads. As for the mouse, I capture when the user clicks or moves the mouse and test what the user is clicking or moving the mouse over with 2 methods...
This captures what the user clicks, I stripped it down, but shows the gist of what Im using it for. I have a button painted at the coords listed in the method. If the user clicks between the coords, a button sound is played, and the start screen flag is changed to 0, which tells the paint method not to paint the start screen. Its a deprecated method, but I like it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public boolean mouseDown(Event e, int x, int y) { mX = x; mY = y;
if(startScreen==1){ if(mX >= 285 && mX <= 385 && mY >= 300 && mY <= 350){ butClick.play(); startScreen = 0; return true; } } else{ return false; } } |
This method constantly checks where the mouse is, if the mouse is over a button, then the hover flag is set to 1, telling the paint method to paint the hover effect on the button and to play the hover effect sound.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public boolean mouseMove(Event evt,int x,int y){ mX = x; mY = y; if(mX > 0 && mY > 0){ if( startScreen == 1){ if(mX >= 285 && mX <= 385 && mY >= 300 && mY <= 350){ if(startHoverFlag == 0){ startHoverFlag = 1; snd_Hover.play(); } } else{ startHoverFlag = 0; } } } else{ return false; } } |
Hopefully this will help you, or someone else can point out any problems they forsee with the above code.