in main. when user press space bar set 'space' to true.
if user let go of space bar set 'space' to false.

Code:
boolean space
boolean shooting = false;

if(space && !shooting)
		{	
			//shoot bullets
			shooting = true;
		}
		if(!space)
		{
			shooting = false;
		}

when user hold space bar than it will only go inside this if statment onces. so it will shoot one bullet. if user want to shoot another bullet than they have to press the space bar again.

is their way to set same effect by only using space variable?

i tried this code below but it doesnt really work. bc this is in game loop so it will keep going in side it.
Code:
boolean space
boolean shooting = false;

if(space)
		{	
			//shoot bullets
		m.setSpace(false);