So, i'm trying to get into java, and i'm trying to make a simple pong game, so i have made the ball and paddle object, but i need to make it so, that the ball will bounce off the paddle like if it was hitting the border, but i can't seem to get the math right here.

This is was i made (It makes the applet freeze by and error though):
Java Code:
public boolean toPaddle(){
		if(x_pos > paddle.getX() || x_pos < paddle.getWidth() || y_pos > paddle.getY() || y_pos < paddle.getHeight()){
			speedx = (rand.nextInt(2)+1)-4; // Changes the direction on the X-axis
			return true;
		return false;
Those are the position methods from the paddle class:
Java Code:
public int getX(){
		return x_pos;
	public int getY(){
		return y_pos;
	public int getWidth(){
		int w = x_pos + p_width;
		return w;
	public int getHeight(){
		int h = y_pos + p_height;
		return h;
I think i made the calculation on the paddle wrong, but this is what i could think off, after seaching a bit.

Regards Naxix