Advertisement
Guest User

Untitled

a guest
May 12th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3.  
  4. public class Rectangle extends Shape
  5. {
  6.  
  7. public Rectangle(int x, int y, int x2, int y2, Color c)
  8. {
  9. super(x, y, x2, y2, c);
  10. }
  11.  
  12. // @Override
  13. public void render(Graphics g)
  14. {
  15.  
  16. g.setColor(getColor());
  17. int w = calcWidth();
  18. int h = calcHeight();
  19.  
  20. if (w <= 0 && h <= 0)
  21. {
  22. w = Math.abs(w);
  23. h = Math.abs(h);
  24.  
  25. g.drawRect(getX2(), getY2(), w, h);
  26.  
  27. }
  28. else if (w < 0 && h >= 0)
  29. {
  30. w = Math.abs(w);
  31. h = Math.abs(h);
  32.  
  33. g.drawRect(getX2(), getY(), w, h);
  34.  
  35. }
  36. else if (w >= 0 && h < 0)
  37. {
  38. w = Math.abs(w);
  39. h = Math.abs(h);
  40.  
  41. g.drawRect(getX(), getY2(), w, h);
  42.  
  43. }
  44. else
  45. {
  46. g.drawRect(getX(), getY(), w, h);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement