Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rectanglecollection;
- /**
- *
- * @author User
- */
- public class Colors implements Comparable<Object>{
- final static int BYTE_MASK=255;
- private long red, green, blue;
- protected long 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 Colors(){}
- public Colors(long c){
- color=c; color2rgb();
- }
- public long getRed()
- { return red;}
- public long getGreen()
- { return green;}
- public long getBlue(){
- return blue;
- }
- public long getColor()
- {return color;}
- public void setRed(long red)
- {this.red=red; rgb2color();}
- public void setGreen(long green)
- {
- this.green=green; rgb2color();
- }
- public void setBlue(long blue)
- {
- this.blue=blue; rgb2color();
- }
- public String toString()
- { return "Red: "+ red + " Green: "+green+ " Blue: "+blue;}
- public boolean equals(Object r)
- {
- return this.color==(((Colors)r).color);
- }
- public int compareTo(Object r)
- {
- if(this.color<((Colors)r).color)
- return -1;
- if(this.color>((Colors)r).color)
- return 1;
- return 0;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement