Only Clicking Once

I have created a menu that could be naviagted with the keys perfecty. However, when I try to implement a mouse supported menu it doesnt seem to work as the click lasts two long no matter how quick you think you did it and so the menu navigates too far away. The code shown below contains the problem, clicking new game in state 1 will go strate to state 8?!

public void mouseReleased(MouseEvent e) {
		if ( e.getButton() == MouseEvent.BUTTON1) {
			if (menuState==1) {menuState = 5;}
			if (menuState==2) {menuState = 5;}
			if (menuState==3) {menuState = 5;}
			if (menuState==4) {menuState = 5;}
			if (menuState==5) {menuState = 8;}
		}
	}
	public void updateMouseForMenu() {
		if (menuState == 1 || menuState == 2 || menuState == 3 || menuState == 4) {
			if (instantMsx > 90 && instantMsx < 200) {
				if (instantMsy > 300 && instantMsy < 330) {
					menuState = 1;
				}
			}
			if (instantMsx > 90 && instantMsx < 200) {
				if (instantMsy > 330 && instantMsy < 360) {
					menuState = 2;
				}
			}
			if (instantMsx > 90 && instantMsx < 200) {
				if (instantMsy > 360 && instantMsy < 390) {
					menuState = 3;
				}
			}
			if (instantMsx > 90 && instantMsx < 200) {
				if (instantMsy > 390 && instantMsy < 420) {
					menuState = 4;
				}
			}
		}
		
		
		if (menuState == 5 || menuState == 6 || menuState == 7) {
			if (instantMsx > 90 && instantMsx < 200) {
				if (instantMsy > 300 && instantMsy < 330) {
					menuState = 5;
				}
			}
			if (instantMsx > 90 && instantMsx < 200) {
				if (instantMsy > 330 && instantMsy < 360) {
					menuState = 6;
				}
			}
			if (instantMsx > 90 && instantMsx < 200) {
				if (instantMsy > 360 && instantMsy < 390) {
					menuState = 7;
				}
			}
		}
	}

Them magic numbers…

Also no shit every time your mouseReleased method is called it will go straight to state 8.

You set menuState to 5 and then check if it’s 5 then set it to 8 so it will always be 8.

To fix:


public void mouseReleased(MouseEvent e) {
      if ( e.getButton() == MouseEvent.BUTTON1) {
         if (menuState==1) {menuState = 5;}
         else if (menuState==2) {menuState = 5;}
         else if (menuState==3) {menuState = 5;}
         else if (menuState==4) {menuState = 5;}
         else if (menuState==5) {menuState = 8;}
      }
   }

Hahaha yeah man that fixed it, wow im retarded :confused: I have been programming for so long I cant see the stupid stuff like that yet I can fix some very complex code problems :confused: