Draw String Using Canvas
This example is used to draw string on different location which is shown in figure. The given code is used to show, how to draw string at different locations.
g.drawString("Top/Left", 0, 0, Graphics.TOP | Graphics.LEFT); g.drawString("Baseline/Center", getWidth() / 2, getHeight() / 2, Graphics.HCENTER | Graphics.BASELINE); g.drawString("Bottom/Right", getWidth(), getHeight(), Graphics.BOTTOM | Graphics.RIGHT); |
In this code the Top/Left is used to draw the string on Top left corner, the Baseline/Center is used to draw the string in center and the Bottom/Right is used to draw the string on the bottom right corner. And the application is as follows:
Source Code of DrawString.java
import javax.microedition.midlet.*;
|