Advertisement
Guest User

Untitled

a guest
May 25th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package triangle;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics2D;
  5. import java.awt.geom.Line2D;
  6.  
  7. public class Triangle {
  8.  
  9. int triLength;
  10. int numOfSides;
  11. Color triColor;
  12.  
  13. int x;
  14. int y;
  15.  
  16. public Triangle (int sides, Color c, int length, int xCoor, int yCoor) {
  17.  
  18. triLength = length;
  19. numOfSides = sides;
  20. triColor = c;
  21.  
  22. x = xCoor;
  23. y = yCoor;
  24. }
  25.  
  26. public void setNew(int sides, Color c, int length, int xCoor, int yCoor) {
  27.  
  28. triLength = length;
  29. numOfSides = sides;
  30. triColor = c;
  31.  
  32. x = xCoor;
  33. y = yCoor;
  34. }
  35.  
  36. public void draw(Graphics2D g2) {
  37.  
  38. g2.setColor(triColor);
  39.  
  40. if (numOfSides == 1) {
  41.  
  42. Line2D.Double one = new Line2D.Double(x, y, x, y + triLength);
  43. g2.draw(one);
  44. }
  45.  
  46. else if (numOfSides == 2) {
  47.  
  48. Line2D.Double one = new Line2D.Double(x, y, x, y + triLength);
  49. Line2D.Double two = new Line2D.Double(x, y + triLength, x + triLength, y + triLength);
  50.  
  51. g2.draw(one);
  52. g2.draw(two);
  53. }
  54.  
  55. else if (numOfSides == 3) {
  56.  
  57. Line2D.Double one = new Line2D.Double(x, y, x, y + triLength);
  58. Line2D.Double two = new Line2D.Double(x, y + triLength, x + triLength, y + triLength);
  59. Line2D.Double three = new Line2D.Double(x, y, x + triLength, y + triLength);
  60.  
  61. g2.draw(one);
  62. g2.draw(two);
  63. g2.draw(three);
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement