Revision as of 18:39, 25 October 2013 by lpvalente (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to display rotated text in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: bogdan.galiceanu (04 Sep 2008)
Last edited: lpvalente (25 Oct 2013)

This article provides a method for displaying rotated text on a canvas in Java ME. The idea is to create an empty image, write the text on it and display it, rotated.

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.Sprite;
public class MyCanvas extends Canvas {
public void paint(Graphics g) {
//The text that will be displayed
String s="java";
//Create the blank image, specifying its size
Image img=Image.createImage(50,50);
//Create an instance of the image's Graphics class and draw the string to it
Graphics gr=img.getGraphics();
gr.drawString(s, 0, 0, Graphics.TOP|Graphics.LEFT);
//Display the image, specifying the rotation value. For example, 90 degrees
g.drawRegion(img, 0, 0, 50, 50, Sprite.TRANS_ROT90, 0, 0, Graphics.TOP|Graphics.LEFT);


Rotated text.JPG

This page was last modified on 25 October 2013, at 18:39.
53 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.