Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aquarium;
- import static java.lang.System.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- public class fish
- {
- public static void main(String[] args)
- {
- new Aquarium();
- }
- }
- class Aquarium extends Frame
- {
- private Fish jacksonFish;
- private boolean isRunning;
- public Aquarium()
- {
- isRunning = false;
- Color blue = new Color(34, 68, 180);
- setBackground(blue);
- setTitle("AQUARIUM");
- setSize(600,400);
- setResizable(false);
- setLocationRelativeTo(null);
- addWindowListener(new WindowAdapter()
- { public void windowClosing(WindowEvent evt){System.exit(0);}});
- setVisible(true);
- jacksonFish = new Fish(240,200);
- start();
- }
- public void paint(Graphics g)
- {
- jacksonFish.image(g);
- }
- public void start()
- {
- isRunning = true;
- run();
- }
- public void run()
- {
- while(isRunning)
- {
- jacksonFish.move();
- repaint();
- delay(1);
- }
- }
- public static void delay(int num)
- {
- try{Thread.sleep(num*10);}
- catch(InterruptedException e){}
- }
- }
- class Fish
- {
- int xPos;
- int yPos;
- double xPrecision;
- double yPrecision;
- int width;
- int height;
- int speed;
- int direction;
- boolean up;
- boolean down;
- public Fish(int x, int y)
- {
- xPos = x;
- xPrecision = x;
- yPos = y;
- yPrecision = y;
- width = 30;
- height = 10;
- speed = 10;
- direction = -1;
- up = false;
- down = false;
- }
- public int getXPos()
- {
- return xPos;
- }
- public int getYPos()
- {
- return yPos;
- }
- public void setXPos()
- {
- }
- public void setYPos()
- {
- }
- public void move()
- {
- Random rand = new Random();
- int change = rand.nextInt(10);
- //int change = (int)rand(random()*10);
- if(change == 0 ) xPos++;
- if(change == 1 ) xPos++;
- if(change == 2 ) xPos++;
- if(change == 3 ) xPos++;
- if(change == 4 ) xPos++;
- if(change == 5 ) xPos--;
- if(change == 6 ) xPos--;
- if(change == 7 ) xPos--;
- if(change == 8 ) xPos--;
- if(change == 9 ) xPos--;
- }
- public void image(Graphics g)
- {
- }
- }
- class Minnow extends Fish
- {
- public Minnow()
- {
- }
- public void image(Graphics g)
- {
- }
- }
Add Comment
Please, Sign In to add comment