# فناوری جاوا > برنامه‌نویسی جاوا > Java ME : نگارش میکرو جاوا > آموزش: کلاس Color برای ارایه ی رنگ های استاندارد

## jalalx

سلام دوستان
 کلاس Color رو برای ارایه ی رنگ های استاندارد درست کردم. شاید برای کسانی که تو کار با رنگ مشکل دارند مفید باشه!

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Jalal
 */
public class Color {

    public int Red;
    public int Green;
    public int Blue;

    public Color(int red, int green, int blue) {
        this.Red = red;
        this.Green = green;
        this.Blue = blue;
    }

    public Color(int rgb){
        this.Red = (rgb & 0x00ff0000) /   0x00010000;
        this.Green = (rgb & 0x0000ff00) / 0x00000100;
        this.Blue = (rgb & 0x000000ff) /  0x00000001;
    }

    public Color() {
        this(0xff, 0xff, 0xff);
    }


    public int getRGB(){
        int rgb = 0x00000000;        
        rgb = (((Red << 0x10) | (Green << 8)) | Blue);        
        return rgb;
    }
    

    public static Color getTransparent() {
        return new Color(255, 255, 255);
    }
    
    
    public static Color getAliceBlue() {
        return new Color(240, 248, 255);
    }

    public static Color getAntiqueWhite() {
        return new Color(250, 235, 215);
    }

    public static Color getAqua() {
        return new Color(0, 255, 255);
    }

    public static Color getAquamarine() {
        return new Color(127, 255, 212);
    }

    public static Color getAzure() {
        return new Color(240, 255, 255);
    }

    public static Color getBeige() {
        return new Color(245, 245, 220);
    }

    public static Color getBisque() {
        return new Color(255, 228, 196);
    }

    public static Color getBlack() {
        return new Color(0, 0, 0);
    }

    public static Color getBlanchedAlmond() {
        return new Color(255, 235, 205);
    }

    public static Color getBlue() {
        return new Color(0, 0, 255);
    }

    public static Color getBlueViolet() {
        return new Color(138, 43, 226);
    }

    public static Color getBrown() {
        return new Color(165, 42, 42);
    }

    public static Color getBurlyWood() {
        return new Color(222, 184, 135);
    }

    public static Color getCadetBlue() {
        return new Color(95, 158, 160);
    }

    public static Color getChartreuse() {
        return new Color(127, 255, 0);
    }

    public static Color getChocolate() {
        return new Color(210, 105, 30);
    }

    public static Color getCoral() {
        return new Color(255, 127, 80);
    }

    public static Color getCornflowerBlue() {
        return new Color(100, 149, 237);
    }

    public static Color getCornsilk() {
        return new Color(255, 248, 220);
    }

    public static Color getCrimson() {
        return new Color(220, 20, 60);
    }

    public static Color getCyan() {
        return new Color(0, 255, 255);
    }

    public static Color getDarkBlue() {
        return new Color(0, 0, 139);
    }

    public static Color getDarkCyan() {
        return new Color(0, 139, 139);
    }

    public static Color getDarkGoldenrod() {
        return new Color(184, 134, 11);
    }

    public static Color getDarkGray() {
        return new Color(169, 169, 169);
    }

    public static Color getDarkGreen() {
        return new Color(0, 100, 0);
    }

    public static Color getDarkKhaki() {
        return new Color(189, 183, 107);
    }

    public static Color getDarkMagenta() {
        return new Color(139, 0, 139);
    }

    public static Color getDarkOliveGreen() {
        return new Color(85, 107, 47);
    }

    public static Color getDarkOrange() {
        return new Color(255, 140, 0);
    }

    public static Color getDarkOrchid() {
        return new Color(153, 50, 204);
    }

    public static Color getDarkRed() {
        return new Color(139, 0, 0);
    }

    public static Color getDarkSalmon() {
        return new Color(233, 150, 122);
    }

    public static Color getDarkSeaGreen() {
        return new Color(143, 188, 139);
    }

    public static Color getDarkSlateBlue() {
        return new Color(72, 61, 139);
    }

    public static Color getDarkSlateGray() {
        return new Color(47, 79, 79);
    }

    public static Color getDarkTurquoise() {
        return new Color(0, 206, 209);
    }

    public static Color getDarkViolet() {
        return new Color(148, 0, 211);
    }

    public static Color getDeepPink() {
        return new Color(255, 20, 147);
    }

    public static Color getDeepSkyBlue() {
        return new Color(0, 191, 255);
    }

    public static Color getDimGray() {
        return new Color(105, 105, 105);
    }

    public static Color getDodgerBlue() {
        return new Color(30, 144, 255);
    }

    public static Color getFirebrick() {
        return new Color(178, 34, 34);
    }

    public static Color getFloralWhite() {
        return new Color(255, 250, 240);
    }

    public static Color getForestGreen() {
        return new Color(34, 139, 34);
    }

    public static Color getFuchsia() {
        return new Color(255, 0, 255);
    }

    public static Color getGainsboro() {
        return new Color(220, 220, 220);
    }

    public static Color getGhostWhite() {
        return new Color(248, 248, 255);
    }

    public static Color getGold() {
        return new Color(255, 215, 0);
    }

    public static Color getGoldenrod() {
        return new Color(218, 165, 32);
    }

    public static Color getGray() {
        return new Color(128, 128, 128);
    }

    public static Color getGreen() {
        return new Color(0, 128, 0);
    }

    public static Color getGreenYellow() {
        return new Color(173, 255, 47);
    }

    public static Color getHoneydew() {
        return new Color(240, 255, 240);
    }

    public static Color getHotPink() {
        return new Color(255, 105, 180);
    }

    public static Color getIndianRed() {
        return new Color(205, 92, 92);
    }

    public static Color getIndigo() {
        return new Color(75, 0, 130);
    }

    public static Color getIvory() {
        return new Color(255, 255, 240);
    }

    public static Color getKhaki() {
        return new Color(240, 230, 140);
    }

    public static Color getLavender() {
        return new Color(230, 230, 250);
    }

    public static Color getLavenderBlush() {
        return new Color(255, 240, 245);
    }

    public static Color getLawnGreen() {
        return new Color(124, 252, 0);
    }

    public static Color getLemonChiffon() {
        return new Color(255, 250, 205);
    }

    public static Color getLightBlue() {
        return new Color(173, 216, 230);
    }

    public static Color getLightCoral() {
        return new Color(240, 128, 128);
    }

    public static Color getLightCyan() {
        return new Color(224, 255, 255);
    }

    public static Color getLightGoldenrodYellow() {
        return new Color(250, 250, 210);
    }

    public static Color getLightGray() {
        return new Color(211, 211, 211);
    }

    public static Color getLightGreen() {
        return new Color(144, 238, 144);
    }

    public static Color getLightPink() {
        return new Color(255, 182, 193);
    }

    public static Color getLightSalmon() {
        return new Color(255, 160, 122);
    }

    public static Color getLightSeaGreen() {
        return new Color(32, 178, 170);
    }

    public static Color getLightSkyBlue() {
        return new Color(135, 206, 250);
    }

    public static Color getLightSlateGray() {
        return new Color(119, 136, 153);
    }

    public static Color getLightSteelBlue() {
        return new Color(176, 196, 222);
    }

    public static Color getLightYellow() {
        return new Color(255, 255, 224);
    }

    public static Color getLime() {
        return new Color(0, 255, 0);
    }

    public static Color getLimeGreen() {
        return new Color(50, 205, 50);
    }

    public static Color getLinen() {
        return new Color(250, 240, 230);
    }

    public static Color getMagenta() {
        return new Color(255, 0, 255);
    }

    public static Color getMaroon() {
        return new Color(128, 0, 0);
    }

    public static Color getMediumAquamarine() {
        return new Color(102, 205, 170);
    }

    public static Color getMediumBlue() {
        return new Color(0, 0, 205);
    }

    public static Color getMediumOrchid() {
        return new Color(186, 85, 211);
    }

    public static Color getMediumPurple() {
        return new Color(147, 112, 219);
    }

    public static Color getMediumSeaGreen() {
        return new Color(60, 179, 113);
    }

    public static Color getMediumSlateBlue() {
        return new Color(123, 104, 238);
    }

    public static Color getMediumSpringGreen() {
        return new Color(0, 250, 154);
    }

    public static Color getMediumTurquoise() {
        return new Color(72, 209, 204);
    }

    public static Color getMediumVioletRed() {
        return new Color(199, 21, 133);
    }

    public static Color getMidnightBlue() {
        return new Color(25, 25, 112);
    }

    public static Color getMintCream() {
        return new Color(245, 255, 250);
    }

    public static Color getMistyRose() {
        return new Color(255, 228, 225);
    }

    public static Color getMoccasin() {
        return new Color(255, 228, 181);
    }

    public static Color getNavajoWhite() {
        return new Color(255, 222, 173);
    }

    public static Color getNavy() {
        return new Color(0, 0, 128);
    }

    public static Color getOldLace() {
        return new Color(253, 245, 230);
    }

    public static Color getOlive() {
        return new Color(128, 128, 0);
    }

    public static Color getOliveDrab() {
        return new Color(107, 142, 35);
    }

    public static Color getOrange() {
        return new Color(255, 165, 0);
    }

    public static Color getOrangeRed() {
        return new Color(255, 69, 0);
    }

    public static Color getOrchid() {
        return new Color(218, 112, 214);
    }

    public static Color getPaleGoldenrod() {
        return new Color(238, 232, 170);
    }

    public static Color getPaleGreen() {
        return new Color(152, 251, 152);
    }

    public static Color getPaleTurquoise() {
        return new Color(175, 238, 238);
    }

    public static Color getPaleVioletRed() {
        return new Color(219, 112, 147);
    }

    public static Color getPapayaWhip() {
        return new Color(255, 239, 213);
    }

    public static Color getPeachPuff() {
        return new Color(255, 218, 185);
    }

    public static Color getPeru() {
        return new Color(205, 133, 63);
    }

    public static Color getPink() {
        return new Color(255, 192, 203);
    }

    public static Color getPlum() {
        return new Color(221, 160, 221);
    }

    public static Color getPowderBlue() {
        return new Color(176, 224, 230);
    }

    public static Color getPurple() {
        return new Color(128, 0, 128);
    }

    public static Color getRed() {
        return new Color(255, 0, 0);
    }

    public static Color getRosyBrown() {
        return new Color(188, 143, 143);
    }

    public static Color getRoyalBlue() {
        return new Color(65, 105, 225);
    }

    public static Color getSaddleBrown() {
        return new Color(139, 69, 19);
    }

    public static Color getSalmon() {
        return new Color(250, 128, 114);
    }

    public static Color getSandyBrown() {
        return new Color(244, 164, 96);
    }

    public static Color getSeaGreen() {
        return new Color(46, 139, 87);
    }

    public static Color getSeaShell() {
        return new Color(255, 245, 238);
    }

    public static Color getSienna() {
        return new Color(160, 82, 45);
    }

    public static Color getSilver() {
        return new Color(192, 192, 192);
    }

    public static Color getSkyBlue() {
        return new Color(135, 206, 235);
    }

    public static Color getSlateBlue() {
        return new Color(106, 90, 205);
    }

    public static Color getSlateGray() {
        return new Color(112, 128, 144);
    }

    public static Color getSnow() {
        return new Color(255, 250, 250);
    }

    public static Color getSpringGreen() {
        return new Color(0, 255, 127);
    }

    public static Color getSteelBlue() {
        return new Color(70, 130, 180);
    }

    public static Color getTan() {
        return new Color(210, 180, 140);
    }

    public static Color getTeal() {
        return new Color(0, 128, 128);
    }

    public static Color getThistle() {
        return new Color(216, 191, 216);
    }

    public static Color getTomato() {
        return new Color(255, 99, 71);
    }

    public static Color getTurquoise() {
        return new Color(64, 224, 208);
    }

    public static Color getViolet() {
        return new Color(238, 130, 238);
    }

    public static Color getWheat() {
        return new Color(245, 222, 179);
    }

    public static Color getWhite() {
        return new Color(255, 255, 255);
    }

    public static Color getWhiteSmoke() {
        return new Color(245, 245, 245);
    }

    public static Color getYellow() {
        return new Color(255, 255, 0);
    }

    public static Color getYellowGreen() {
        return new Color(154, 205, 50);
    }
}




مثالی برای نحوه ی استفاده:

public void paint(Graphic g){
    g.setColor(Color.getWhite().toRGB());
    g.drawRec(0,0, getWidth(), getHeight());
}

----------

