Java examples for javax.microedition.lcdui:Graphics
draw Vertical Gradient Border 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 drawVerticalGradientBorder(Graphics g, int objX, int objY, int objWidth, int objHeight, int color1, int color2) { if (color1 == color2) { g.setColor(color1);/* w w w .j av a 2s . c o m*/ g.drawRect(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); objHeight--; objWidth--; if (isLightGraphics) { /** Drawing rectangle for middle color **/ g.setColor((sRed__ - pRed__) / 2 + pRed__, (sGreen - pGreen) / 2 + pGreen, (sBlue_ - pBlue_) / 2 + pBlue_); g.drawRect(objX, objY, objWidth, objHeight); } else { /** Drawing horizontal lines **/ g.setColor(color1); g.drawLine(objX, objY, objX + objWidth, objY); g.setColor(color2); g.drawLine(objX, objY + objHeight, objX + objWidth, objY + objHeight); /** Drawing vertical lines **/ 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, objY + y); g.drawLine(objX + objWidth, objY + y, objX + objWidth, objY + y); } } } } }