Java Reference
In-Depth Information
public void startApp() {
Display.getDisplay(this).setCurrent(mFontCanvas);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) {
notifyDestroyed();
return;
}
boolean isBold = mFontCanvas.isBold() ^ (c == mBoldCommand);
boolean isItalic = mFontCanvas.isItalic() ^ (c == mItalicCommand);
boolean isUnderline = mFontCanvas.isUnderline() ^
(c == mUnderlineCommand);
int style =
(isBold ? Font.STYLE_BOLD : 0) |
(isItalic ? Font.STYLE_ITALIC : 0) |
(isUnderline ? Font.STYLE_UNDERLINED : 0);
mFontCanvas.setStyle(style);
mFontCanvas.repaint();
}
}
Measuring Text
The Font class can tell you useful information about the dimensions of text. If you read the
previous example carefully, you'll notice we already used one of these methods, getHeight() .
This method returns the height of an entire line of text and can be used to position multiple lines.
If you really need to know the location of the baseline, call getBaselinePosition() . This
returns the distance from the top of a line of text to the baseline. However, given the flexibility
offered by the anchor points in Graphics , you probably won't ever need to find the baseline
yourself.
The rest of the methods in Font for measuring text measure the width of various pieces
of text. The names and parameters of these methods are the same as text drawing methods
in Graphics :
public int charWidth(char ch)
public int charsWidth(char ch, int offset, int length)
public int stringWidth(String str)
public int substringWidth(String str, int offset, int len)
Search WWH ::




Custom Search