Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Billington. email: mlbillington@fcps.edu
- // version: 7.25.2007
- // updated by Phil Ero 16NOV07
- import java.awt.*;
- import javax.swing.ImageIcon;
- public class world
- {
- private double myX; // x and y coordinates of center
- private double myY;
- private double myDiameter;
- private Color myColor;
- private double myRadius;
- // constructors
- public world() //default constructor
- {
- myX = 150;
- myY = 150;
- myDiameter = 50;
- myColor = Color.red;
- myRadius = myDiameter/2;
- }
- public world(double x, double y, double d, Color c)
- {
- myX = x;
- myY = y;
- myDiameter = d;
- myColor = c;
- myRadius = d/2;
- }
- // accessor methods
- public double getX()
- {
- return myX;
- }
- public double getY()
- {
- return myY;
- }
- public double getDiameter()
- {
- return myDiameter;
- }
- public Color getColor()
- {
- return myColor;
- }
- public double getRadius()
- {
- return myRadius;
- }
- // modifier methods
- public void setX(double x)
- {
- myX = x;
- }
- public void setY(double y)
- {
- myY=y;
- }
- public void setColor(Color c)
- {
- myColor = c;
- }
- public void setDiameter(double d)
- {
- myDiameter = d;
- myRadius = d/2;
- }
- public void setRadius(double r)
- {
- myRadius = r*2;
- myDiameter = 3*r;
- }
- // instance methods
- public void jump(int rightEdge, int bottomEdge)
- {
- // moves location to random (x, y) within the edges
- myX = (Math.random()* (rightEdge-myDiameter) + myRadius);
- myY = (Math.random()* (bottomEdge-myDiameter) + myRadius);
- }
- public void draw(Graphics myBuffer)
- {
- myBuffer.setColor(myColor);
- ImageIcon ico=new ImageIcon("boo.png");
- myBuffer.drawImage(ico.getImage(), (int)(myX-myRadius), (int)(myY-myRadius), (int)myDiameter, (int)myDiameter, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement