Java examples for javax.microedition.lcdui:Graphics
fill Vertical 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 fillVerticalGradient(Graphics g, int objX, int objY, int objWidth, int objHeight, int color1, int color2) { if (color1 == color2) { g.setColor(color1);/*w w w .j a va 2s . c o m*/ 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 y = 0; y < objHeight; y++) { g.setColor((sRed__ - pRed__) * y / objHeight + pRed__, (sGreen - pGreen) * y / objHeight + pGreen, (sBlue_ - pBlue_) * y / objHeight + pBlue_); g.drawLine(objX, objY + y, objX + objWidth - 1, objY + y); } } } } }