Note that there are some explanatory texts on larger screens.

plurals
  1. PODraw squares between two points
    primarykey
    data
    text
    <p>I'm working on some exercises and I've been stuck on this for some hours now (quite new to Java). Anyhow, this is what I'm supposed to do: When I run the program I will have a square in the middle of the screen and when I then click somewhere within that screen another square will be drawn at the place where I clicked and in-between these two points there are supposed to be 10 squares. So wherever I click there should always be 10 squares drawn between.</p> <p>However, I can't make it to function properly.</p> <p>This is what I've managed to do so far:</p> <pre><code>import se.lth.cs.ptdc.window.SimpleWindow; import se.lth.cs.ptdc.square.Square; public class PrintSquares2 { public static void main(String[] args) { SimpleWindow w = new SimpleWindow(600, 600, "PrintSquares2"); int posX = 300; int posY = 300; int loop = 0; System.out.println("Skriv rotation"); Square sq1 = new Square(posX,posY,200); sq1.draw(w); w.waitForMouseClick(); int destX = w.getMouseX(); int destY = w.getMouseY(); System.out.println("Dest X: " + destX + " Dest Y: " + destY); System.out.println("Pos X: " + posX + " Pos Y: " + posY); SimpleWindow.delay(10); //sq1.erase(w); int jumpX = (destX - posX) / 10; int jumpY = (destY - posY) / 10; System.out.println(jumpX); while (posX &lt; destX) { posX = posX+10; SimpleWindow.delay(100); loop++; System.out.println("Loop: " + loop); System.out.println("Dest X: " + destX + " Dest Y: " + destY); System.out.println("Pos X: " + posX + " Pos Y: " + posY); Square sq2 = new Square(posX,posY,200); sq2.draw(w); } while (posX &gt; destX) { posX = posX-10; SimpleWindow.delay(100); loop++; System.out.println("Loop: " + loop); System.out.println("Dest X: " + destX + " Dest Y: " + destY); System.out.println("Pos X: " + posX + " Pos Y: " + posY); sq1.draw(w); Square sq2 = new Square(posX,posY,200); sq2.draw(w); } while (posY &lt; destY) { posY = posY+10; SimpleWindow.delay(100); loop++; System.out.println("Loop: " + loop); System.out.println("Dest X: " + destX + " Dest Y: " + destY); System.out.println("Pos X: " + posX + " Pos Y: " + posY); sq1.draw(w); Square sq2 = new Square(posX,posY,200); sq2.draw(w); } while (posY &gt; destY) { posY = posY-10; SimpleWindow.delay(100); loop++; System.out.println("Loop: " + loop); System.out.println("Dest X: " + destX + " Dest Y: " + destY); System.out.println("Pos X: " + posX + " Pos Y: " + posY); sq1.draw(w); Square sq2 = new Square(posX,posY,200); sq2.draw(w); } SimpleWindow.delay(10); sq1.draw(w); //SimpleWindow.clear(w); } </code></pre> <p>}</p> <p>I'm pretty sure that I overcomplicated everything since this should be pretty basic.</p> <p>The end result is supposed to look like this: <a href="http://i.stack.imgur.com/ZxUM2.png" rel="nofollow">End result</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload