Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. package sk.paz1a.practicals.zadanie4;
  2.  
  3. import java.awt.Color;
  4. import java.awt.event.MouseEvent;
  5.  
  6. import sk.upjs.jpaz2.*;
  7.  
  8. public class ClickPane extends WinPane {
  9.  
  10. int pocitadlo = 0;
  11. double pozXPrvej = -50;
  12. double pozYPrvej = -50;
  13. double pozX1;
  14. double pozY1;
  15. double pozX2;
  16. double pozY2;
  17.  
  18. public void drawDot(double x, double y) {
  19. // metoda na kreslenie bodky a cisla na suradnice
  20. Turtle raphaello = new Turtle();
  21. this.add(raphaello);
  22. raphaello.setFillColor(Color.orange);
  23. raphaello.setPosition(x, y);
  24. raphaello.dot(10);
  25. raphaello.turn(90);
  26. String cisloPrint = Integer.toString(pocitadlo);
  27. raphaello.printCenter(cisloPrint);
  28. this.remove(raphaello);
  29. }
  30.  
  31. protected void onMouseClicked(int x, int y, MouseEvent detail) {
  32. if (pocitadlo == 0) {
  33. pocitadlo++;
  34. this.drawDot(x, y);
  35. pozXPrvej = x;
  36. pozYPrvej = y;
  37. pozX1 = pozXPrvej;
  38. pozY1 = pozYPrvej;
  39. pozX2 = pozX1;
  40. pozY2 = pozY1;
  41. } else if (Math.sqrt(Math.pow(x - pozXPrvej, 2) + Math.pow(y - pozYPrvej, 2)) <= 10) {
  42. Turtle raphaello = new Turtle();
  43. this.add(raphaello);
  44. raphaello.setPosition(pozX2, pozY2);
  45. raphaello.moveTo(pozXPrvej, pozYPrvej);
  46. this.remove(raphaello);
  47. this.drawDot(pozX2, pozY2);
  48. pocitadlo = 1;
  49. this.drawDot(pozXPrvej, pozYPrvej);
  50. pocitadlo = 0;
  51.  
  52. } else {
  53. pozX2 = x;
  54. pozY2 = y;
  55. Turtle raphaello = new Turtle();
  56. this.add(raphaello);
  57. raphaello.setPosition(pozX1, pozY1);
  58. raphaello.moveTo(pozX2, pozY2);
  59. this.remove(raphaello);
  60. this.drawDot(pozX1, pozY1);
  61. pocitadlo++;
  62. this.drawDot(pozX2, pozY2);
  63. pozX1 = pozX2;
  64. pozY1 = pozY2;
  65. }
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement