ホームに戻る
abcと書く
/*
* abcと書く
*/
import com.nttdocomo.ui.*;
public class abc extends IApplication
{
nmCanvas nmc;
public void start() {
nmc = new nmCanvas();
Display.setCurrent(nmc);
}
public class nmCanvas extends Canvas
{
String s = "abc";
int font_width;
int font_height;
int position_x;
int position_y;
int screen_width;
int screen_height;
public nmCanvas()
{
// ソフトキーの右側を「終了」にする
setSoftLabel(Frame.SOFT_KEY_2, "終了");
// スクリーンの幅と高さを取得
screen_width = getWidth();
screen_height = getHeight();
// デフォルトのフォントを取得
Font font = Font.getDefaultFont();
// 文字列のフォント情報を取得
font_width = font.stringWidth(s);
font_height = font.getHeight();
// 文字列を中央に表示するための位置を算出
position_x = (screen_width - font_width) / 2;
position_y = (screen_height + font_height) / 2;
}
public void paint(Graphics g)
{
// 描画をロック
g.lock();
// 画面のクリア
g.clearRect(0, 0, screen_width, screen_height);
// 文字列の描画
g.drawString(s, position_x, position_y);
// ロックの解除
g.unlock(true);
}
public void processEvent(int nType, int nParm)
{
if(nType == Display.KEY_PRESSED_EVENT) {
switch(nParm) {
case Display.KEY_SOFT2:
// 終了
IApplication.getCurrentApp().terminate();
break;
}
}
this.repaint();
}
}
}
画面の中央に abc と書きます