Revision as of 14:32, 4 June 2009 by tanjaluodes (Talk | contribs)

How to display rotated text in Java ME

From Nokia Developer Wiki
Jump to: navigation, search

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

73 page views in the last 30 days.