HelloCanvas.java
/*
* Copyright © 2011 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
import javax.microedition.lcdui.*;
public class HelloCanvas extends Canvas {
boolean messageVisible = true;
public HelloCanvas() {
}
public void newMessage() {
messageVisible = !messageVisible;
repaint();
}
public void paint(Graphics g) {
int w = getWidth();
int h = getHeight();
g.setColor(0, 51, 240); // blue
g.fillRect(0, 0, w, h);
//display the message
if (messageVisible) {
Font font = g.getFont();
int fontHeight = font.getHeight();
//set the text color
g.setColor(255, 255, 255); // white
//write the strings in the center of the screen
g.drawString("Hello, world!", w / 2, (h - fontHeight) / 2, Graphics.TOP | Graphics.HCENTER);
}
}
}