Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. implements Comparable<Object> {
  2. final static int BYTE_MASK=255;
  3. private long red, green, blue;
  4. protected long color;
  5. public void rgb2color()
  6. {
  7. color=(red<<16)|(green<<8)|(blue);
  8. }
  9. public void color2rgb()
  10. {
  11. red=color>>16;
  12. green=(color>>8) & BYTE_MASK;
  13. blue=color & BYTE_MASK;
  14. }
  15. public Color() {}
  16. public Color(long c)
  17. {
  18. this.color=c;
  19. color2rgb();
  20. }
  21. public long getRed()
  22. {
  23. return red;
  24. }
  25.  
  26. public void setRed(long r)
  27. {
  28. this.red=r;
  29. rgb2color();
  30. }
  31. public long getGreen()
  32. {
  33. return green;
  34. }
  35.  
  36. public void setGreen(long g)
  37. {
  38. this.green=g;
  39. rgb2color();
  40. }
  41. public long getBlue()
  42. {
  43. return blue;
  44. }
  45.  
  46. public void setBlue(long b)
  47. {
  48. this.blue=b;
  49. rgb2color();
  50. }
  51.  
  52. public String toString()
  53. {
  54. return "Red: "+red+", Green: "+green+", Blue: "+blue+", Color: "+color;
  55. }
  56.  
  57. public boolean equals(Object r)
  58. {
  59. return this.color==((Color)r).color;
  60. }
  61.  
  62. public int compareTo(Object c)
  63. {
  64. if(this.color<((Color)c).color) return -1;
  65. if(this.color>((Color)c).color) return 1;
  66. return 0;
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement