Hello, digit348 here. Im currently working on remaking the original mario game for my APCS class and im stuck on trying to get the jump mechanics for him to work. Following is the current movement code i have:

Code:
public void keyPressed(KeyEvent e){
		int key = e.getKeyCode();
		int Max = 400;
		int Min = 10;
		
		if(x >= Max){
			dx = 0;
		}else if(x <=Min){
			dx =0;
		}else{
			if (key == KeyEvent.VK_UP){
				if(jumpCounter >0){
					dy = -2;
					jumpCounter = jumpCounter - 1;
					setJumping(true);
					}
			}else if (key == KeyEvent.VK_DOWN){
				dy = 2;
			}else if (key == KeyEvent.VK_LEFT){
				dx = -3;
				ImageIcon l = new ImageIcon("mImages/MarioSL2.gif");
				still = l.getImage();
			}else if (key == KeyEvent.VK_RIGHT){
				dx = 3;
				ImageIcon r = new ImageIcon("mImages/MarioSR2.gif");
				still = r.getImage();
			}else if(key == KeyEvent.VK_UP && key == KeyEvent.VK_RIGHT){
				dy = 2;
				dx = 3;
			}
		}
	}
	
	
	public void keyReleased(KeyEvent e){
		int key = e.getKeyCode();
		
		if(key == KeyEvent.VK_UP){
			dy = 0;
		}else if (key == KeyEvent.VK_DOWN){
			dy = 0;
		}else if (key == KeyEvent.VK_LEFT){
			dx = 0;
		}else if (key == KeyEvent.VK_RIGHT){
			dx = 0;
		}
		ImageIcon i = new ImageIcon("mImages/MarioSS.gif");
		still = i.getImage();
		if(x >= 400){
			x = 398;
		}else if(x <=10){
			x = 15;
		}
	}
The movement and jumping is handled through these:

Code:
public void move(){
		x = x+ dx;
	}
	public void jump(){
			y = y +dy;
	}
	public int getX(){
		return x;
	}
	
	public int getY(){
		return y;
	}
Finally i have the list of booleans i was attempting to use to control the jumping that i tried previously:

Code:
public void setJumping(boolean jumping){
	    this.jumping=jumping;
	    }
	  public boolean isJumping(){
	    return jumping;
	    }
	  
	public void setFalling(boolean falling){
		this.falling=falling;
		}
	public boolean isFalling(){
		  return falling;
		  }

	public void setOnGround(boolean onGround){
		  this.onGround=onGround;
		  }
	public boolean isOnGround(){
		  return onGround;
		  }
What i was attempting to do with the booleans was basiclly, if isFalling = true and isOnGround = false then he needs to be affected by gravity, however he needs to hit the max height be for this can happen.

Code:
public static int MAX_JUMP = 100;
Meaning he needs to be able to jump the 100 pixels, and then have gravity take effect on his sprite, causing him to return to the ground but not breaking the current collisions and sending him through it. (Done that more than a few times).

If anyother parts from my code would be helpful, please tell me and ill have them up shortly. Any and all help is greatly appreciated.