Guest User

Untitled

a guest
Feb 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. package aquarium;
  2.  
  3.  
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import java.awt.geom.*;
  8. import java.util.*;
  9.  
  10. public class aquariumFish
  11. {
  12. public static void main(String[] args)
  13. {
  14. Aquarium toTest = new Aquarium();
  15.  
  16. }
  17. }
  18.  
  19. class Aquarium extends Frame
  20. {
  21. Fish siddharth;
  22. private boolean isRunning;
  23.  
  24. Aquarium()
  25. {
  26. isRunning = false;
  27. siddharth = new redFish(100,100);
  28. Color blue = new Color(34, 68, 180);
  29. Color red = new Color(201, 44, 37);
  30.  
  31. setBackground(blue);
  32. setForeground(red);
  33. setTitle("Sid's Aquarium");
  34. setSize(600,400);
  35. setResizable(false);
  36. setLocationRelativeTo(null);
  37. addWindowListener(new WindowAdapter()
  38. { public void windowClosing(WindowEvent evt){System.exit(0);}});
  39.  
  40.  
  41.  
  42. start();
  43.  
  44. setVisible(true);
  45. }
  46.  
  47. public void paint(Graphics g)
  48. {
  49. siddharth.image(g);
  50.  
  51. }
  52.  
  53. private void start()
  54. {
  55. isRunning = true;
  56. run();
  57. }
  58.  
  59. private void run()
  60. {
  61. while(isRunning)
  62. {
  63. siddharth.move();
  64. repaint();
  65. delay(1);
  66. }
  67. }
  68.  
  69. private static void delay(int num)
  70. {
  71. try{Thread.sleep(num*100);}
  72. catch(InterruptedException e){}
  73. }
  74. }
  75.  
  76. class Fish
  77. {// MAKES THESE NOTHING, DELETE THE PROTECTED
  78. protected int xPos;
  79. protected int yPos;
  80. protected double xPrecision;
  81. protected double yPrecision;
  82. protected int width;
  83. protected int height;
  84. protected int direction;
  85. protected int speed;
  86. protected boolean up;
  87. protected boolean down;
  88.  
  89. public Fish()
  90. {
  91.  
  92. }
  93.  
  94. public int getXPos()
  95. {
  96. return xPos;
  97. }
  98.  
  99. public int getYPos()
  100. {
  101. return yPos;
  102. }
  103.  
  104. public void setXPos(int x)
  105. {
  106. xPos = x;
  107. }
  108.  
  109. public void setYPos(int y)
  110. {
  111. yPos = y;
  112. }
  113.  
  114. void move()
  115. {
  116.  
  117. }
  118.  
  119. public void image(Graphics g)
  120. {
  121.  
  122. }
  123. }
  124.  
  125. class redFish extends Fish
  126. {
  127. Graphics2D g2d;
  128.  
  129. private redFish()
  130. {
  131.  
  132. }
  133.  
  134. public redFish(int x, int y)
  135. {
  136. xPos = x;
  137. yPos = y;
  138. xPrecision = x;
  139. yPrecision = y;
  140. }
  141.  
  142. void move()
  143. {
  144. Random rand = new Random();
  145. int change = rand.nextInt(10);
  146.  
  147. if(change == 0 ) xPos++;
  148. if(change == 1 ) xPos++;
  149. if(change == 2 ) xPos++;
  150. if(change == 3 ) xPos++;
  151. if(change == 4 ) xPos++;
  152. if(change == 5 ) xPos--;
  153. if(change == 6 ) xPos--;
  154. if(change == 7 ) xPos--;
  155. if(change == 8 ) xPos--;
  156. if(change == 9 ) xPos--;
  157. }
  158.  
  159. public void image(Graphics g)
  160. {
  161. g.setColor(Color.red);
  162. g.fillOval(100,100,120,40);
  163. g.fillOval(220,98,20,45);
  164.  
  165.  
  166.  
  167. g.setColor(Color.black);
  168. g.fillOval(110,110,20,20);
  169.  
  170. g.setColor(Color.white);
  171. g.fillOval(115,115,10,10);
  172.  
  173. g.setColor(Color.black);
  174. g.drawLine(130,130,135,110);
  175. g.drawLine(133,130,138,110);
  176. g.drawLine(137,130,141,110);
  177.  
  178.  
  179.  
  180.  
  181. }
  182. }
Add Comment
Please, Sign In to add comment