本文整理汇总了Java中javax.microedition.lcdui.Graphics.getFont方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.getFont方法的具体用法?Java Graphics.getFont怎么用?Java Graphics.getFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.lcdui.Graphics
的用法示例。
在下文中一共展示了Graphics.getFont方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintTextRow
import javax.microedition.lcdui.Graphics; //导入方法依赖的package包/类
/**
* Renders a text row to Canvas.
*/
private int paintTextRow(Graphics g, String text, int x, int y) {
int w = getWidth();
Font font = g.getFont();
for (int j = 0; j < text.length(); j++) {
char c = text.charAt(j);
int cw = font.charWidth(c);
if (x + cw > w) {
x = 0;
y += font.getHeight();
}
g.drawChar(c, x, y, Graphics.TOP | Graphics.LEFT);
x += cw;
}
if (touch || nHD_portrait) {
y += (2 * font.getHeight());
} else {
y += font.getHeight();
}
return y;
}
示例2: paintContent
import javax.microedition.lcdui.Graphics; //导入方法依赖的package包/类
protected void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g) {
if(player != null) {
//center stuff
width = rightBorder - leftBorder;
int offsetX = (width - cw) / 2;
vc.setDisplayLocation(x + offsetX, y);
if(!playing) {
vc.setVisible(false);
Font f = g.getFont();
int fnth = f.getHeight();
//Calculate margins and locations
int mx = x + offsetX;
int my = y;
int mw = vc.getDisplayWidth();
int mh = vc.getDisplayHeight();
int hi = Math.max((int)Math.floor(.2 * mh), fnth);
int fh = mh - hi * 2;
//int fw = mw - wi * 2;
//int wi = (int)Math.floor(.2 * mw);
int fw = (int)Math.floor(.9 * fh);
int wi = (mw - fw)/2;
int wu = (int)Math.floor(fw / 5.0);
int hu = (int)Math.floor(fh / 7.0);
if(hashKeyImage == null) {
hashKeyImage = ImageUtils.getImage(imageLocation);
if(hashKeyImage != null){
//scale
int[] newDimension = ImageUtils.getNewDimensions(hashKeyImage, fw,fh);
if(newDimension[0] != height || newDimension[1] != width) {
hashKeyImage = ImageUtils.resizeImage(hashKeyImage, newDimension[1], newDimension[0]);
}
}
}
if(hashKeyImage != null) {
g.drawImage(hashKeyImage, mx + wi + fw / 2, my + hi + fh / 2, Graphics.HCENTER | Graphics.VCENTER);
} else {
//Draw us a big 'ol hash
g.setColor(0, 0, 0);
g.fillRect(mx + wi + wu, my + hi, wu, fh);
g.fillRect(mx + wi + 3 * wu, my + hi, wu, fh);
g.fillRect(mx + wi, my + hi + 2 * hu, fw, hu);
g.fillRect(mx + wi, my + hi + 4 * hu, fw, hu);
}
int tw = f.stringWidth(top);
int bw = f.stringWidth(bottom);
int tx = (mw - tw)/2 + mx;
int tyo = (hi - fnth) /2;
int ty = my + tyo;
g.drawString(top, tx, ty, Graphics.TOP | Graphics.LEFT);
int bx = (mw - bw)/2 + mx;
int by = (my + mh - hi) + tyo;
g.drawString(bottom, bx, by, Graphics.TOP | Graphics.LEFT);
}
}
}
示例3: paintContent
import javax.microedition.lcdui.Graphics; //导入方法依赖的package包/类
protected void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g) {
if(player != null) {
//center stuff
width = rightBorder - leftBorder;
int offsetX = (width - cw) / 2;
vc.setDisplayLocation(x + offsetX, y);
if(!playing) {
vc.setVisible(false);
Font f = g.getFont();
int fnth = f.getHeight();
//Calculate margins and locations
int mx = x + offsetX;
int my = y;
int mw = vc.getDisplayWidth();
int mh = vc.getDisplayHeight();
int hi = Math.max((int)Math.floor(.2 * mh), fnth);
int fh = mh - hi * 2;
//int fw = mw - wi * 2;
//int wi = (int)Math.floor(.2 * mw);
int fw = (int)Math.floor(.9 * fh);
int wi = (mw - fw)/2;
int wu = (int)Math.floor(fw / 5.0);
int hu = (int)Math.floor(fh / 7.0);
//Draw us a big 'ol hash
g.setColor(0, 0, 0);
g.fillRect(mx + wi + wu, my + hi, wu, fh);
g.fillRect(mx + wi + 3 * wu, my + hi, wu, fh);
g.fillRect(mx + wi, my + hi + 2 * hu, fw, hu);
g.fillRect(mx + wi, my + hi + 4 * hu, fw, hu);
String top = Localization.get("video.playback.top");
//String top = "lw: " + vc.getSourceWidth() + " lh: " + vc.getSourceHeight();
String bottom = Localization.get("video.playback.bottom");
//String bottom = "cw: " + cw + " ch: " + ch;
int tw = f.stringWidth(top);
int bw = f.stringWidth(bottom);
int tx = (mw - tw)/2 + mx;
int tyo = (hi - fnth) /2;
int ty = my + tyo;
g.drawString(top, tx, ty, Graphics.TOP | Graphics.LEFT);
int bx = (mw - bw)/2 + mx;
int by = (my + mh - hi) + tyo;
g.drawString(bottom, bx, by, Graphics.TOP | Graphics.LEFT);
}
}
}