Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1.  
  2.  
  3. import java.awt.*; // Using AWT's Graphics and Color
  4. import javax.swing.*; // Using Swing's components and containers
  5. import java.util.Timer;
  6. import java.util.TimerTask;
  7.  
  8. public class start extends JFrame {
  9. public static final int CANVAS_WIDTH = 1300;
  10. public static final int CANVAS_HEIGHT = 500;
  11.  
  12. int[][] pos = {
  13. {20, 300},
  14. {40, 270},
  15. {60, 240}
  16. };
  17. boolean gone1 = false;
  18. boolean gone2 = false;
  19. boolean gone3 = false;
  20. boolean gone4 = false;
  21. boolean gone5 = false;
  22. boolean gone6 = false;
  23. boolean gone7 = false;
  24. boolean gone8 = false;
  25. boolean gone9 = false;
  26. boolean gone10 = false;
  27. boolean gone11 = false;
  28. boolean gone12 = false;
  29. boolean gone13 = false;
  30. boolean gone14 = false;
  31. boolean gone15 = false;
  32. boolean gone16 = false;
  33. boolean gone17 = false;
  34. boolean gone18 = false;
  35. boolean gone19 = false;
  36. boolean gone20 = false;
  37. Timer timer = new Timer();
  38.  
  39. private DrawCanvas canvas;
  40.  
  41.  
  42. public static void main(String[] args) {
  43. // Run the GUI codes on the Event-Dispatching thread for thread safety
  44. SwingUtilities.invokeLater(new Runnable() {
  45. public void run() {
  46. new start(); // Let the constructor do the job
  47. }
  48. });
  49. }
  50.  
  51. public start() {
  52. canvas = new DrawCanvas(); // Construct the drawing canvas
  53. canvas.setPos(pos);
  54. canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
  55.  
  56. // Set the Drawing JPanel as the JFrame's content-pane
  57. Container cp = getContentPane();
  58. cp.add(canvas);
  59. // or "setContentPane(canvas);"
  60.  
  61. setDefaultCloseOperation(EXIT_ON_CLOSE); // Handle the CLOSE button
  62. pack(); // Either pack() the components; or setSize()
  63. setTitle("Hanoi"); // "super" JFrame sets the title
  64. setVisible(true); // "super" JFrame show
  65.  
  66. timer.scheduleAtFixedRate(new TimerTask() {
  67. @Override
  68. public void run() {
  69. if (!gone1 && pos[2][1] > 150) pos[2][1] -= 1; //góra mały
  70. else if (!gone1 && pos[2][0] < 860) {//prwo mały
  71. pos[2][0] += 2;
  72. if (pos[2][0] == 860) gone1 = true;
  73. } else if (!gone2 && pos[2][1] < 300) {//dół maly
  74. pos[2][1] += 1;
  75. if (pos[2][1] == 300) gone2 = true;
  76. } else if (!gone3 && pos[1][1] > 150) {//góra średni
  77. pos[1][1] -= 1;
  78. if (pos[1][1] == 150) gone3 = true;
  79. } else if (!gone4 && pos[1][0] < 440) {//prawo średni
  80. pos[1][0] += 2;
  81. if (pos[1][0] == 440) gone4 = true;
  82. } else if (!gone5 && pos[1][1] < 300) {//dół średni
  83. pos[1][1] += 1;
  84. if (pos[1][1] == 300) gone5 = true;
  85. } else if (!gone6 && pos[2][1] > 150) {//góra mały
  86. pos[2][1] -= 1; //góra mały
  87. if (pos[2][1] == 150) gone6 = true;
  88. } else if (!gone7 && pos[2][0] > 460) {//lewo mały
  89. pos[2][0] -= 2;
  90. if (pos[2][0] == 460) gone7 = true;
  91. } else if (!gone8 && pos[2][1] < 270) {//dół maly
  92. pos[2][1] += 1;
  93. if (pos[2][1] == 270) gone8 = true;
  94. } else if (!gone9 && pos[0][1] > 150) {
  95. pos[0][1] -= 1;
  96. if (pos[0][1] == 150) gone9 = true;
  97. } else if (!gone10 && pos[0][0] < 820) {
  98. pos[0][0] += 2;
  99. if (pos[0][0] == 820) gone10 = true;
  100. } else if (!gone11 && pos[0][1] < 300) {
  101. pos[0][1] += 1;
  102. if (pos[0][1] == 300) gone11 = true;
  103. } else if (!gone12 && pos[2][1] > 150) {//góra mały
  104. pos[2][1] -= 1; //góra mały
  105. if (pos[2][1] == 150) gone12 = true;
  106. } else if (!gone13 && pos[2][0] > 60) {//lewo mały
  107. pos[2][0] -= 2;
  108. if (pos[2][0] == 60) gone13 = true;
  109. } else if (!gone14 && pos[2][1] < 300) {//dół maly
  110. pos[2][1] += 1;
  111. if (pos[2][1] == 300) gone14 = true;
  112. } else if (!gone15 && pos[1][1] > 150) {//góra średni
  113. pos[1][1] -= 1;
  114. if (pos[1][1] == 150) gone15 = true;
  115. } else if (!gone16 && pos[1][0] < 840) {//prawo średni
  116. pos[1][0] += 2;
  117. if (pos[1][0] == 840) gone16 = true;
  118. } else if (!gone17 && pos[1][1] < 270) {//dół średni
  119. pos[1][1] += 1;
  120. if (pos[1][1] == 270) gone17 = true;
  121. } else if (!gone18 && pos[2][1] > 150) {
  122. pos[2][1] -= 1; //góra mały
  123. if(pos[2][1] == 150) gone18 = true;
  124. } else if (!gone19 && pos[2][0] < 860) {//prwo mały
  125. pos[2][0] += 2;
  126. if (pos[2][0] == 860) gone19 = true;
  127. } else if (!gone20 && pos[2][1] < 240) {//dół maly
  128. pos[2][1] += 1;
  129. if (pos[2][1] == 240) gone20 = true;
  130. }
  131. canvas.revalidate(pos);
  132. canvas.repaint();
  133. }
  134. }, 1, 1);
  135.  
  136.  
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement