Draw rectangle : Rectangle « J2ME « Java Tutorial






Draw rectangle
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

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

class LineCanvas extends Canvas {
  public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    g.setColor(0);
    g.setStrokeStyle(Graphics.SOLID);

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

  }
}








31.33.Rectangle
31.33.1.Fill rectangleFill rectangle
31.33.2.Draw rectangleDraw rectangle
31.33.3.Fill Round RectangleFill Round Rectangle
31.33.4.Fill a rectangle, and a round rectangleFill a rectangle, and a round rectangle