Advertisement
fursty

OOP2 Color

Mar 2nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package color;
  2.  
  3. public class rgb implements Comparable<Object>{
  4. final static int BYTE_MASK=255;
  5. private long red,blue,green;
  6. private long color;
  7. public void rgb2color() {
  8. color=(red<<16)|(green<<8)|(blue);
  9. }
  10. public void color2rgb() {
  11. red=color>>16;
  12. green=(color>>8)&BYTE_MASK;
  13. blue = color&BYTE_MASK;
  14. }
  15. public rgb() {}
  16. public rgb(int redcolor, int bluecolor, int greencolor) {
  17. this.red = redcolor;
  18. this.blue = bluecolor;
  19. this.green = greencolor;
  20. }
  21. public long getred(){
  22. return red;
  23. }
  24. public long getblue(){
  25. return blue;
  26. }
  27. public long getgreen(){
  28. return green;
  29. }
  30. public void setred(long r) {
  31. red=r;
  32. }
  33. public void setblue(long r) {
  34. blue=r;
  35. }
  36. public void setgreen(long r) {
  37. green=r;
  38. }
  39. public String toString() {
  40. return "Red:"+red+",Green:"+green+",Blue:"+blue+",Compound:"+color;
  41. }
  42. public boolean equals(Object r) {
  43. return this.color==((rgb)r).color;}
  44. public int compareTo(Object c) {
  45. if(this.color<((rgb)c).color) return-1;
  46. if(this.color>((rgb)c).color) return 1;
  47. return 0;
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement