Advertisement
Guest User

oktay

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