Java examples for javax.microedition.lcdui:Graphics
fill Sharp Horizontal Gradient micro edition
import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; public class Main{ public static boolean isLightGraphics = false; /** Primary colors **/ private static int pRed__ = 0; private static int pGreen = 0; private static int pBlue_ = 0; /** Secondary colors **/ private static int sRed__ = 0; private static int sGreen = 0; private static int sBlue_ = 0; public static void fillSharpHorizontalGradient(Graphics g, int objX, int objY, int objWidth, int objHeight, int color1, int color2, int color3, int color4) { int objWidthHalf = objWidth / 2; fillHorizontalGradient(g, objX, objY, objWidthHalf, objHeight, color1, color2);/*w ww . j av a 2s .c om*/ objX += objWidthHalf; fillHorizontalGradient(g, objX, objY, objWidthHalf, objHeight, color3, color4); } public static void fillHorizontalGradient(Graphics g, int objX, int objY, int objWidth, int objHeight, int color1, int color2) { if (color1 == color2) { g.setColor(color1); g.fillRect(objX, objY, objWidth, objHeight); } else { /** Primary colors **/ pRed__ = (color1 & 0xFF0000) >> 16; pGreen = (color1 & 0x00FF00) >> 8; pBlue_ = (color1 & 0x0000FF); /** Secondary colors **/ sRed__ = (color2 & 0xFF0000) >> 16; sGreen = (color2 & 0x00FF00) >> 8; sBlue_ = (color2 & 0x0000FF); if (isLightGraphics) { /** Drawing rectangle for middle color **/ g.setColor((sRed__ - pRed__) / 2 + pRed__, (sGreen - pGreen) / 2 + pGreen, (sBlue_ - pBlue_) / 2 + pBlue_); g.fillRect(objX, objY, objWidth, objHeight); } else { /** Drawing gradient **/ for (int x = 0; x < objWidth; x++) { g.setColor((sRed__ - pRed__) * x / objWidth + pRed__, (sGreen - pGreen) * x / objWidth + pGreen, (sBlue_ - pBlue_) * x / objWidth + pBlue_); g.drawLine(objX + x, objY, objX + x, objY + objHeight - 1); } } } } }