Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Color implements Comparable<Object>{
- private static long BYTE_MASK=255;
- private long red,green,blue,color;
- public void rgb2color()
- {
- color=red<<16|green<<8|blue;
- }
- public void color2rgb()
- {
- red=color>>16;
- green=(color>>8)&BYTE_MASK;
- blue=color&BYTE_MASK;
- }
- public Color() {}
- public Color(long c)
- {
- color=c;
- color2rgb();
- }
- public long getRed()
- {
- return red;
- }
- public void setRed(long r)
- {
- red=r;
- rgb2color();
- }
- public long getGreen()
- {
- return green;
- }
- public void setGreen(long g)
- {
- green=g;
- rgb2color();
- }
- public long getBlue()
- {
- return blue;
- }
- public void setBlue(long b)
- {
- blue=b;
- rgb2color();
- }
- public long getColor()
- {
- return color;
- }
- public String toString()
- {
- return "Red:" + red +
- ",Green:" + green +
- ",Blue:" + blue +
- ",RGB:" + color;
- }
- public boolean equals(Object r) {
- return this.color==((Color)r).color;}
- public int compareTo(Object c) {
- if(this.color<((Color)c).color)return -1;
- if(this.color>((Color)c).color)return 1;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement