import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.rnicroedition.lcdui.CornmandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
/**
Отображает некоторый текст, «нарисованный» в Canvas.
Демонстрирует использование процедур рисования текста в Graphics.
@смотри javax.microedition.lcdui.Graphics
*/
public class TextDemo extends Canvas
implements CommandListener
}
public void paint(Graphics g)
}
paintClipRect(g);
int width = getWidth (); int height = "getHeight ();
g. setFont(Font.getDefault Font());
g. drawStriny("Default", 5, 30, Graphics.LEFT I Graphics.BOTTOM);
g. setFont (Font.get Font (Font.FACE_SYSTEM, Font.STYLE_PLAIN,
Font.SIZE_LARGE)); g.drawstring("Large", 5, 53, Graphics.LEFT | Graphics.BOTTOM);
g. set Font(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_ITALIC,
Font.SIZE_MEDIUM));
g. drawString("Medium", 5, 71, Graphics.LEFT I Graphics.BOTTOM);
g. set Font(Font.get Font(Font.FACE_PROPORTIONAL, Font.STYLE_UNDERLINED,
Font.SIZE_SMALL));
g. drawString("Small", 5, 90, Graphics.LEFT I Graphics.BOTTOM);
g. setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,
Font.SIZE_MEDIUM));
g. drawString ("V", width — 10, 20, Graphics.RIGHT I Graphics.BOTTOM)
g. drawStringC'E", width — 10, 32, Graphics.RIGHT I Graphics.BOTTOM)
g. drawString("R", width — 10, 44, Graphics.RIGHT I Graphics.BOTTOM)
g. drawStringC'T", width — 10, 56, Graphics.RIGHT I Graphics.BOTTOM)
g. drawString("I", width — 10, 68, Graphics.RIGHT I Graphics.BOTTOM)
g. drawString ("C", width — 10, 80, Graphics.RIGHT | Graphics.BOTTOM)
g. drawStringC'A", width — 10, 92, Graphics.RIGHT I Graphics.BOTTOM) g.drawString ("L", width — 10, 104, Graphics.RIGHT I Graphics.BOTTOM);
g. drawChar('B', width — 25, 20, Graphics.RIGHT | Graphics.BOTTOM);
g. drawChar(0, width — 25, 32, Graphics.RIGHT I Graphics.BOTTOM);:
g. drawChar('L', width — 25, 44, Graphics.RIGHT I Graphics.BOTTOM);:
g. drawChar ('D', width — 25, 56, Graphics.RIGHT I Graphics.BOTTOM);
}
.
}
Эта демонстрационная программа выбирает, где разместить текстовые строки «Default», «Large», «Medium» и «Small», располагая основные линии ограничивающих прямоугольников. Текст также выравнивается по левому краю. Обратите внимание, что логический OR горизонтальной и вертикальной политик привязки (LEFT | BOTTOM) указывают позицию привязки.
Две строки «BOLD» и «VERTICAL» нарисованы вертикально простым размещением отдельных символов с помощью метода