Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sk.paz1a.practicals.zadanie4;
- import java.awt.Color;
- import java.awt.event.MouseEvent;
- import sk.upjs.jpaz2.*;
- public class ClickPane extends WinPane {
- int pocitadlo = 0;
- double pozXPrvej = -50;
- double pozYPrvej = -50;
- double pozX1;
- double pozY1;
- double pozX2;
- double pozY2;
- public void drawDot(double x, double y) {
- // metoda na kreslenie bodky a cisla na suradnice
- Turtle raphaello = new Turtle();
- this.add(raphaello);
- raphaello.setFillColor(Color.orange);
- raphaello.setPosition(x, y);
- raphaello.dot(10);
- raphaello.turn(90);
- String cisloPrint = Integer.toString(pocitadlo);
- raphaello.printCenter(cisloPrint);
- this.remove(raphaello);
- }
- protected void onMouseClicked(int x, int y, MouseEvent detail) {
- if (pocitadlo == 0) {
- pocitadlo++;
- this.drawDot(x, y);
- pozXPrvej = x;
- pozYPrvej = y;
- pozX1 = pozXPrvej;
- pozY1 = pozYPrvej;
- pozX2 = pozX1;
- pozY2 = pozY1;
- } else if (Math.sqrt(Math.pow(x - pozXPrvej, 2) + Math.pow(y - pozYPrvej, 2)) <= 10) {
- Turtle raphaello = new Turtle();
- this.add(raphaello);
- raphaello.setPosition(pozX2, pozY2);
- raphaello.moveTo(pozXPrvej, pozYPrvej);
- this.remove(raphaello);
- this.drawDot(pozX2, pozY2);
- pocitadlo = 1;
- this.drawDot(pozXPrvej, pozYPrvej);
- pocitadlo = 0;
- } else {
- pozX2 = x;
- pozY2 = y;
- Turtle raphaello = new Turtle();
- this.add(raphaello);
- raphaello.setPosition(pozX1, pozY1);
- raphaello.moveTo(pozX2, pozY2);
- this.remove(raphaello);
- this.drawDot(pozX1, pozY1);
- pocitadlo++;
- this.drawDot(pozX2, pozY2);
- pozX1 = pozX2;
- pozY1 = pozY2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement