dimanche 4 octobre 2015

Using break to stop the moving lines in java

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:

  1. Move Label 1
  2. Move Label 2
  3. compare label 1's and label 2's position (when the text hits and its on each other) "Using 'if' statement"
  4. Once on top, stop it by "using 'break' statement"
  5. 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;
            }
    }
}

Aucun commentaire:

Enregistrer un commentaire