Hi all, I'm new to java and I need help changing the direction of these balls from a horizontal axis to a vertical axis bouncing in the center. I've tried reversing the integers but there seems to be something i've missed.
package package_bouncingball; import java.applet.*; import java.awt.*; import javax.swing.*; import javax.swing.event.*; public class Class_bouncingball extends Applet implements Runnable { int x_pos1 = 150; int y_pos1 = 200; int radius1 = 20; int x_pos2 = 250; int y_pos2 = 200; int radius2 = 20; private float ballspeedx1 = -3; private float ballspeedy1 = 0; private float ballspeedx2 = 3; private float ballspeedy2 = 0; public void init() {} public void start() { Thread th = new Thread (this); th.start (); } public void stop() {} public void destroy() {} public void run () { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while (true) { x_pos1 += ballspeedx1; y_pos1 += ballspeedy1; x_pos2 += ballspeedx2; y_pos2 += ballspeedy2; repaint(); if (x_pos1 < 100) { ballspeedx1 = -ballspeedx1; x_pos1 = 100; } if (x_pos2 < 100) { ballspeedx2 = -ballspeedx2; x_pos2 = 100; } if (x_pos1 > 300) { ballspeedx1 = -ballspeedx1; x_pos1 = 300; } if (x_pos2 > 300) { ballspeedx2 = -ballspeedx2; x_pos2 = 300; } if (Math.abs(x_pos2-x_pos1)<radius1+radius2){ ballspeedx1 = -ballspeedx1; ballspeedx2 = -ballspeedx2; } try { Thread.sleep (20); } catch (InterruptedException ex) {} Thread.currentThread().setPriority(Thread.MAX_PRIORITY); }} public void paint (Graphics g) { g.setColor (Color.red); g.fillOval (x_pos1 - radius1, y_pos1 - radius1, 2 * radius1, 2 * radius1); g.setColor (Color.blue); g.fillOval (x_pos2 - radius2, y_pos2 - radius2, 2 * radius2, 2 * radius2); g.setColor(Color.black); g.drawLine(80,80,80,320); // left g.drawLine(320,80,320,320); // right g.drawLine(80,80,320,80); // g.drawLine(80,320,320,320); // } }