Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. // Billington. email: mlbillington@fcps.edu
  2. // version: 7.25.2007
  3. // updated by Phil Ero 16NOV07
  4.  
  5. import java.awt.*;
  6. import javax.swing.ImageIcon;
  7.  
  8. public class world
  9. {
  10. private double myX; // x and y coordinates of center
  11. private double myY;
  12. private double myDiameter;
  13. private Color myColor;
  14. private double myRadius;
  15. // constructors
  16. public world() //default constructor
  17. {
  18. myX = 150;
  19. myY = 150;
  20. myDiameter = 50;
  21. myColor = Color.red;
  22. myRadius = myDiameter/2;
  23. }
  24. public world(double x, double y, double d, Color c)
  25. {
  26. myX = x;
  27. myY = y;
  28. myDiameter = d;
  29. myColor = c;
  30. myRadius = d/2;
  31. }
  32. // accessor methods
  33. public double getX()
  34. {
  35. return myX;
  36. }
  37. public double getY()
  38. {
  39. return myY;
  40. }
  41. public double getDiameter()
  42. {
  43. return myDiameter;
  44. }
  45. public Color getColor()
  46. {
  47. return myColor;
  48. }
  49. public double getRadius()
  50. {
  51. return myRadius;
  52. }
  53. // modifier methods
  54. public void setX(double x)
  55. {
  56. myX = x;
  57. }
  58. public void setY(double y)
  59. {
  60. myY=y;
  61. }
  62. public void setColor(Color c)
  63. {
  64. myColor = c;
  65. }
  66. public void setDiameter(double d)
  67. {
  68. myDiameter = d;
  69. myRadius = d/2;
  70. }
  71. public void setRadius(double r)
  72. {
  73. myRadius = r*2;
  74. myDiameter = 3*r;
  75. }
  76. // instance methods
  77. public void jump(int rightEdge, int bottomEdge)
  78. {
  79. // moves location to random (x, y) within the edges
  80. myX = (Math.random()* (rightEdge-myDiameter) + myRadius);
  81. myY = (Math.random()* (bottomEdge-myDiameter) + myRadius);
  82. }
  83. public void draw(Graphics myBuffer)
  84. {
  85. myBuffer.setColor(myColor);
  86. ImageIcon ico=new ImageIcon("boo.png");
  87. myBuffer.drawImage(ico.getImage(), (int)(myX-myRadius), (int)(myY-myRadius), (int)myDiameter, (int)myDiameter, null);
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement