Basically, Im just trying out a very simple collision test for another program Im working on, but it does seem to so simple (Or maybe Im just an idiot!) Anyway, here is the code:
public void run() {
while(true){
try {
if(rect.rect.intersects(rect1.rect)){
System.out.println("Test1");
if(rect1.x == ((rect.x + rect.width)-1)){
System.out.println("Test2");
rect1.x = rect.x + rect.width;
rect1.dx = 0;
}
}
rect.update();
rect1.update();
Thread.sleep(50);
The program does not get to test2!
Any help to solve this issue is greatly appreciated! Thanks in advance!
Paint component part:
public void paintComponent(Graphics g){
rect1.paint(g);
rect2.paint(g);
g.drawString(String.valueOf(rect1.x), 100, 100);
g.drawString(String.valueOf(rect2.x+rect2.width), 100, 150);
repaint();
}
Image:

Run the program in Eclipse (or your preferred IDE) and use its runtime debug facilities to set a breakpoint at the first if statement. Then step through and examine the values of the variables. Hopefully this will make clear why your code is failing to do what you expect.