Set color and gray scale : Graphics « J2ME « Java Tutorial

Set color and gray scale
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

public class DrawRectGraphicsMIDlet extends MIDlet {
  private Display display;
  protected void startApp() {
    Canvas canvas = new LineCanvas();
    display = Display.getDisplay(this);
  protected void pauseApp() {
  protected void destroyApp(boolean unconditional) {

class LineCanvas extends Canvas {
  public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();

        g.drawRect(width/4, 0, width/2, height/4);


31.26.1.Set colorSet color
31.26.2.Set stroke styleSet stroke style
31.26.3.Set Gray styleSet Gray style
31.26.4.Set color and gray scaleSet color and gray scale
31.26.5.Get stroke styleGet stroke style
31.26.6.Translate coordinateTranslate coordinate
31.26.7.Change stroke style between drawingChange stroke style between drawing