|
How to get the size of mobile screen |
|
|
Canvas class of javax.microedition.lcdui package gives faciltiy of low level
level graphics on mobile. An application gets the drawing area by methods
getWidth() and getHeight().
The illustration below draws a rectangle on the mobile device's screen:
public void paint(Graphics g)
{
// get the dimensions of the screen:
int width = getWidth ();
int height = getHeight();
// clear the screen (paint it white):
g.setColor(0xffffff);
g.fillRect(0, 0, width, height);
Font font = g.getFont();
int fontHeight = font.getHeight();
int fontWidth = font.stringWidth("Hello World!");
// set the text color to red:
g.setColor(255, 0, 0);
g.setFont(font);
g.drawString("Hello World!", (width - fontWidth)/2,
(height - fontHeight)/2,g.TOP|g.LEFT);
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.