Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aquarium;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.geom.*;
- import java.util.*;
- public class aquariumFish
- {
- public static void main(String[] args)
- {
- Aquarium toTest = new Aquarium();
- }
- }
- class Aquarium extends Frame
- {
- Fish siddharth;
- private boolean isRunning;
- Aquarium()
- {
- isRunning = false;
- siddharth = new redFish(100,100);
- Color blue = new Color(34, 68, 180);
- Color red = new Color(201, 44, 37);
- setBackground(blue);
- setForeground(red);
- setTitle("Sid's Aquarium");
- setSize(600,400);
- setResizable(false);
- setLocationRelativeTo(null);
- addWindowListener(new WindowAdapter()
- { public void windowClosing(WindowEvent evt){System.exit(0);}});
- start();
- setVisible(true);
- }
- public void paint(Graphics g)
- {
- siddharth.image(g);
- }
- private void start()
- {
- isRunning = true;
- run();
- }
- private void run()
- {
- while(isRunning)
- {
- siddharth.move();
- repaint();
- delay(1);
- }
- }
- private static void delay(int num)
- {
- try{Thread.sleep(num*100);}
- catch(InterruptedException e){}
- }
- }
- class Fish
- {// MAKES THESE NOTHING, DELETE THE PROTECTED
- protected int xPos;
- protected int yPos;
- protected double xPrecision;
- protected double yPrecision;
- protected int width;
- protected int height;
- protected int direction;
- protected int speed;
- protected boolean up;
- protected boolean down;
- public Fish()
- {
- }
- public int getXPos()
- {
- return xPos;
- }
- public int getYPos()
- {
- return yPos;
- }
- public void setXPos(int x)
- {
- xPos = x;
- }
- public void setYPos(int y)
- {
- yPos = y;
- }
- void move()
- {
- }
- public void image(Graphics g)
- {
- }
- }
- class redFish extends Fish
- {
- Graphics2D g2d;
- private redFish()
- {
- }
- public redFish(int x, int y)
- {
- xPos = x;
- yPos = y;
- xPrecision = x;
- yPrecision = y;
- }
- void move()
- {
- Random rand = new Random();
- int change = rand.nextInt(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)
- {
- g.setColor(Color.red);
- g.fillOval(100,100,120,40);
- g.fillOval(220,98,20,45);
- g.setColor(Color.black);
- g.fillOval(110,110,20,20);
- g.setColor(Color.white);
- g.fillOval(115,115,10,10);
- g.setColor(Color.black);
- g.drawLine(130,130,135,110);
- g.drawLine(133,130,138,110);
- g.drawLine(137,130,141,110);
- }
- }
Add Comment
Please, Sign In to add comment