I am completely new to java and I have one problem I am trying to resolve. I am using ACM Library for my purpose. My goal is the following:
- Move Label 1
- Move Label 2
- Compare label 1's and label 2's position (when the text hits and its on each other) "Using 'if' statement"
- Once on top, stop it by using
break
statement. - Restart the cycle.
If someone could help me out by explaining how this can be implemented. That would be awesome. I am trying to learn. Thank you!
import acm.graphics.GLabel;
import acm.program.CommandLineProgram;
import acm.program.GraphicsProgram;
public class Main extends GraphicsProgram {
public void run( )
{
int label1_xy = 50;
int label2_xy = 200;
GLabel label1 = new GLabel("Hello World.");
add(label1, label1_xy,label1_xy);
GLabel label2 = new GLabel("Goodbye World.");
add(label2, label2_xy,label2_xy);
while (true)
{
label1.move(10,10);
pause(500);
label2.move(-10,-10);
break;
}
}
}