×
Namespaces

Variants
Actions
(Difference between revisions)

How to display rotated text in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix categories)
lpvalente (Talk | contribs)
m (Lpvalente -)
 
Line 20: Line 20:
 
}}
 
}}
  
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.
+
{{Abstract|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.}}
  
 
<code java>
 
<code java>

Latest revision as of 21:39, 25 October 2013

Article Metadata
Article
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);
}
 
}


Screenshot:

Rotated text.JPG

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