Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. package tiltmaze;
  2.  
  3. import java.awt.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6.  
  7.  
  8. public class TiltMaze extends JPanel implements ActionListener
  9. {
  10. Timer time = new Timer(5, this);//Declares variable
  11. Image Pic;//Declares variable
  12. int PicW = 363;//Declares variable
  13. int PicH = 362;//Declares variable
  14. int Start = 0;//Declares variable
  15. int x = 15;//Declares variable
  16. int y = 115;//Declares variable
  17. int speed = 3;//Declares variable
  18.  
  19. public TiltMaze ()
  20. {
  21. ImageIcon obj = new ImageIcon("src/tilt2.jpg"); //Gets image
  22. Pic = obj.getImage(); //Sets image to a variable
  23. }
  24. public void paint(Graphics g)
  25. {
  26. super.paint(g);
  27. g.drawImage(Pic, Start, 0, null);//Makes the image in /src painted
  28. g.setColor(Color.white);//Sets colour for next entries
  29. g.fillRect(15, 110, 30, 35);//Fills in a rectangle
  30. g.setColor(Color.green);//Sets colour for next entries
  31. g.fillOval(x, y, 25, 25);//Fills in the oval that will be moving
  32. g.setColor(Color.black);//Sets colour for next entries
  33. g.drawOval(x, y, 25, 25);//Makes an outline of the oval
  34.  
  35. time.start();
  36. }
  37. public void actionPerformed(ActionEvent e)
  38. {
  39. if(x > 14 && x < 215 && y == 115) //Draws circle moving
  40. {
  41. x = x + speed + 1;
  42. repaint();//Repaints image after variable changes removing old image
  43. }
  44. if(x == 215 && y > 114 && y < 217)//Draws circle moving
  45. {
  46. y = y + speed;
  47. repaint();//Repaints image after variable changes removing old image
  48. }
  49. if(y == 217 && x > 168 && x < 218)//Draws circle moving
  50. {
  51. x = x - speed;
  52. repaint();//Repaints image after variable changes removing old image
  53. }
  54. if(x == 167 && y > 216 && y < 315)//Draws circle moving
  55. {
  56. y = y + speed;
  57. repaint();//Repaints image after variable changes removing old image
  58. }
  59. if(y == 316 && x < 169 && x > 16)//Draws circle moving
  60. {
  61. x = x - speed;
  62. repaint();//Repaints image after variable changes removing old image
  63. }
  64. if(x == 14 && y < 318 && y > 216)//Draws circle moving
  65. {
  66. y = y - speed;
  67. repaint();//Repaints image after variable changes removing old image
  68. }
  69. if(y == 217 && x > 13 && x < 65)//Draws circle moving
  70. {
  71. x = x + speed;
  72. repaint();//Repaints image after variable changes removing old image
  73. }
  74. if(x == 65 && y < 219 && y > 170)//Draws circle moving
  75. {
  76. y = y - speed;
  77. repaint();//Repaints image after variable changes removing old image
  78. }
  79. if( y == 169 && x > 64 && x < 167)//Draws circle moving
  80. {
  81. x = x + speed + 1;
  82. repaint();//Repaints image after variable changes removing old image
  83. }
  84. if(x == 169 && y < 170 && y > 20)//Draws circle moving
  85. {
  86. y = y - speed - 1;
  87. repaint();//Repaints image after variable changes removing old image
  88. }
  89. if(y == 17 && x < 170 && x > 65)//Draws circle moving
  90. {
  91. x = x - speed;
  92. repaint();//Repaints image after variable changes removing old image
  93. }
  94. if(x == 64 && y > 16 && y < 60)//Draws circle moving
  95. {
  96. y = y + speed;
  97. repaint();//Repaints image after variable changes removing old image
  98. }
  99. if(y == 62 && x > 63 && x < 112)//Draws circle moving
  100. {
  101. x = x + speed;
  102. repaint();//Repaints image after variable changes removing old image
  103. }
  104. if(x == 112 && y > 61 && y < 212)//Draws circle moving
  105. {
  106. y = y + speed + 1;
  107. repaint();//Repaints image after variable changes removing old image
  108. }
  109. }
  110.  
  111.  
  112. public static void main(String[] args)
  113. {
  114. TiltMaze m = new TiltMaze();
  115. JFrame f = new JFrame("Tilt Maze Solution");//Name of JFrame
  116. f.add(m);
  117. f.setSize(373, 395);//Size of JFrame
  118. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//When JFrame is closed program finishes running
  119. f.setLocationRelativeTo(null);
  120. f.setVisible(true);
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement