- 浏览: 2114199 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
ratlsun:
想请教下uc最新版本在android4.2和4.3版本上是不是 ...
UC浏览器8.3 (for iPhone)设计理念.“無”为而设 -
gly0920sky520123:
很有用哦,谢谢
DOS命令大全(经典收藏) -
chenyu0748:
UC加油,花哥加油~
UC浏览器8.3 (for iPhone)设计理念.“無”为而设 -
cnliuyix:
LZ搞点更有层次的吧,介个一般工程里根本用不到这么简单的。Si ...
Android 设计一个可单选,多选的Demo -
gang4415:
rgz03407@163.com
JSR规范,系统参数测试大全
Contents [hide]
1 Overview
2 Source code: FontSizingMIDlet.java
3 Source code: FontCanvas.java
4 Example application
5 See also
[edit]
Overview
In MIDlets the font and its properties are specified by using the standard LCDUI javax.microedition.lcdui.Font class. A font has three properties: size, style and face. In MIDP these properties have the following values:
Font size
SIZE_SMALL
SIZE_MEDIUM
SIZE_LARGE
Font style
STYLE_PLAIN
STYLE_BOLD
STYLE_ITALIC
STYLE_UNDERLINED
or a combination of STYLE_BOLD, STYLE_ITALIC, and STYLE_UNDERLINED
Font face
FACE_SYSTEM
FACE_MONOSPACE
FACE_PROPORTIONAL
Having only three sizes has been especially a limitation and this has been improved in the latest Java Runtimes for S60. It is now possible to use a new getFont() method in com.nokia.mid.ui.DirectUtils class:
public static Font getFont(int face, int style, int height)
face - one of FACE_SYSTEM, FACE_MONOSPACE, or FACE_PROPORTIONAL
style - STYLE_PLAIN, or a combination of STYLE_BOLD, STYLE_ITALIC, and STYLE_UNDERLINED
height - font height in pixels
This improvement is part of Nokia UI API 1.2, which is included in Java Runtime 1.3 for S60. Here is a full working sample MIDlet code below. The FontSizingMIDlet reads shows sample text on the screen and the font size and style can be changed by using the buttons on the touch screen. Because touch screen is used, this MIDlet works only in devices having one(for example, Nokia 5800 XpressMusic and N97).
[edit]
Source code: FontSizingMIDlet.java
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
public class FontSizingMIDlet extends MIDlet {
private FontCanvas canvas;
public void startApp() {
canvas = new FontCanvas(this);
Display.getDisplay(this).setCurrent(canvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
protected void showError(String title, String text) {
Alert alert = new Alert(title, text, null, AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
alert.getType().playSound(Display.getDisplay(this));
Displayable current = Display.getDisplay(this).getCurrent();
if (current instanceof Alert) {}
else Display.getDisplay(this).setCurrent(alert);
}
}
[edit]
Source code: FontCanvas.java
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import com.nokia.mid.ui.DirectUtils;
import com.nokia.mid.ui.TactileFeedback;
public class FontCanvas extends Canvas implements CommandListener {
private FontSizingMIDlet midlet;
private Command exitCommand;
private String heightString = "";
private String fontString = "";
private Font font;
private int fontHeight = 20;
private int buttonFontHeight = 20;
private int face = 0;
private int style = 0;
private int edge = 0;
private int width;
private int height;
private TactileFeedback tactileFeedback;
private boolean touchFeedback = false;
private Button plusButton;
private Button minusButton;
private Button styleButton;
private boolean init = false;
public FontCanvas(FontSizingMIDlet midlet) {
this.midlet = midlet;
exitCommand = new Command("Exit", Command.EXIT, 1);
this.addCommand(exitCommand);
this.setCommandListener(this);
tactileFeedback = new TactileFeedback();
touchFeedback = tactileFeedback.isTouchFeedbackSupported();
}
public void paint(Graphics g) {
if (!init) {
width = getWidth();
height = getHeight();
plusButton = new Button(60, 25, "HEIGHT+");
minusButton = new Button(60, 25, "HEIGHT-");
styleButton = new Button(60, 25, "STYLE");
}
heightString = "Font height = " + fontHeight;
fontString = "Style = " + style + ", face = " + face;
g.setColor(255, 255,255);
g.fillRect(0, 0, width, height);
g.setColor(0, 0, 0);
font = DirectUtils.getFont(face, style, fontHeight);
fontHeight = font.getHeight();
g.setFont(font);
g.drawString(heightString, 0, 0, Graphics.TOP|Graphics.LEFT);
g.drawString(fontString, 0, fontHeight, Graphics.TOP|Graphics.LEFT);
g.drawString("com.nokia.mid.ui.version: " + System.getProperty("com.nokia.mid.ui.version"),
0, fontHeight*2, Graphics.TOP|Graphics.LEFT); // Should return "1.2"
edge = plusButton.drawButton(g, 10, height-70, plusButton.selected);
edge = minusButton.drawButton(g, edge+10, height-70, minusButton.selected);
edge = styleButton.drawButton(g, edge+10, height-70, styleButton.selected);
if (!init) {
plusButton.registerFeedbackArea(this, 0);
minusButton.registerFeedbackArea(this, 1);
styleButton.registerFeedbackArea(this, 2);
init = true; // initialization done
}
}
protected void keyPressed(int keyCode) {
if (keyCode == -2 || keyCode == -3) {
if (fontHeight > 0) fontHeight--;
}
else if (keyCode == -1 || keyCode == -4) fontHeight++;
repaint(0, 0, width, fontHeight*3+2);
}
protected void keyReleased(int keyCode) { }
protected void keyRepeated(int keyCode) {
if (keyCode == -2 || keyCode == -3) {
if (fontHeight > 0) fontHeight--;
}
else if (keyCode == -1 || keyCode == -4) fontHeight++;
repaint(0, 0, width, fontHeight*3+2);
}
protected void pointerDragged(int x, int y) { }
protected void pointerPressed(int x, int y) {
plusButton.selected = false;
minusButton.selected = false;
styleButton.selected = false;
if (checkButton(plusButton, x, y)) {
plusButton.selected = true;
fontHeight++;
}
else if (checkButton(minusButton, x, y)) {
minusButton.selected = true;
if (fontHeight > 0) fontHeight--;
}
else if (checkButton(styleButton, x, y)) {
styleButton.selected = true;
if (style < 7) style++;
else style = 0;
}
repaint();
}
protected void pointerReleased(int x, int y) {
plusButton.selected = false;
minusButton.selected = false;
styleButton.selected = false;
repaint();
}
protected void sizeChanged(int w, int h) {
width = w;
height = h;
repaint();
}
private boolean checkButton(Button button, int x, int y) {
boolean pressed = false;
boolean horizontal = false;
boolean vertical = false;
int x_edge = button.x + button.w;
int y_edge = button.y + button.h;
if (x > button.x && x < x_edge) horizontal = true;
if (y > button.y && y < y_edge) vertical = true;
if (horizontal && vertical) pressed = true;
return pressed;
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
midlet.notifyDestroyed();
}
}
class Button {
private int x=0;
private int y=0;
private int w=0;
private int h=0;
private int size=0;
private String text="";
protected boolean selected = false;
protected Button(int h, int size, String text) {
this.h = h;
this.size = size;
this.text = text;
}
public void registerFeedbackArea(Canvas canvas, int id) {
if (touchFeedback) {
try {
tactileFeedback.registerFeedbackArea(canvas, id, x, y, w, h,
TactileFeedback.FEEDBACK_STYLE_BASIC);
}
catch (IllegalArgumentException iae) {
System.out.println("IllegalArgumentException: " + iae.getMessage());
}
}
}
public int drawButton(Graphics g, int x, int y, boolean selected) {
this.x = x;
this.y = y;
font = DirectUtils.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, size);
buttonFontHeight = font.getHeight();
g.setFont(font);
this.w = font.stringWidth(text)+ 10;
g.setColor(255, 0, 0);
g.drawRect(x, y, w, h);
if (selected) g.setColor(0, 0, 255);
g.drawRect(x-1, y-1, w+2, h+2);
g.setColor(0, 0, 0);
g.drawString(text, x+w/2, y+h/2-buttonFontHeight/2, Graphics.TOP|Graphics.HCENTER);
edge = x + w;
return edge;
}
}
}
In the screenshots below font sizes of 12, 30 and 50 pixels have been used.
There are also the FontSizingMIDlet.jad and FontSizingMIDlet.jar files available here.
[edit]
Example application
FontSizingMIDlet.zip containing FontSizingMIDlet.jad and FontSizingMIDlet.jar
[edit]
See also
How to retrieve version number of Java Runtime for S60
发表评论
-
汉字点阵字库原理
2011-01-28 10:09 3386一、 汉字编码 1. ... -
如何通过改jad和Manifest把其它手机的java游戏改成N830的
2011-01-25 10:21 1361首先要明确一点,不是所有的游戏都能改的。 <200 ... -
索爱手机IMSI序列号获取
2011-01-20 11:29 1963国际移动用户识别码(I ... -
J2ME数组的复制及连接操作
2010-11-19 10:47 1271public class Arrays { /** ... -
手机 J2ME MIDP 性能测试工具(MIDP BenchMark)
2010-11-19 10:35 1462JavaME Test Suitehttp://www.dog ... -
SocketConnection 参数详细介绍
2010-03-23 11:34 2135请大家看下面的代码: len = is.read(gDat ... -
J2ME使用Socket通过cmwap接入点访问安全HTTPS
2010-03-17 16:36 484这个问题是在我升级J2ME版XHTML浏览器的时候被引入的 ... -
一些很特别的J2ME开源项目(转
2010-03-11 09:43 2360StrutsME 一个轻量级的序列化协议,使J2ME客户端能调 ... -
WMLC 检查charset编码
2009-12-16 15:27 180http://www.iana.org/assignments ... -
Eclipse快捷键
2009-12-01 10:38 1418编辑相关快捷键 Eclipse的编辑功能非常强大,掌 ... -
改善你的J2ME程序界面-使用开源UI库
2009-09-03 16:45 3703J2ME自带UI不是太美观,使用起来也不太方面,为了解决这 ... -
LZW数据压缩算法的原理分析【转】
2009-08-05 19:31 2574转一篇好文章, 原文地址:http://www.cnblog ... -
<a> 标签,target="blank",target="_blank" 的区别。
2009-05-27 13:00 11559在编写html代码的时候。 target="bla ... -
贡献 高效的MIDlet 编程
2009-05-23 15:32 1902从网上找到这本资料。 是E文版的。 大家顺便锻炼下E文 -
How to use pop-up TextBox in Java ME
2009-05-23 13:44 1773Overview One of the Displayabl ... -
A Simple Ordered Hashtable
2009-05-23 12:08 1563This article illustrates how to ... -
开发NokiaS40系列应用程序初级篇
2009-05-22 18:56 1721本文讲述如何搭建Nokia S40系列手机应用程序的开发环境 ... -
索尼爱立信手机在 J2ME 程序中的字体大小
2009-05-18 16:25 1349之前有朋友问到索尼爱立信手机在 J2me 程序中的字体大小,请 ... -
If-Modified-Since & If-None-Match
2009-05-13 11:01 14555google告诉网站站长:您 ... -
WAP 2.0介绍和使用规范
2009-05-08 16:09 11454—— XHTML MP and WCSS一、WAP的常识(省略 ...
相关推荐
You should ensure that the server's public keys are loaded by the client as described in How to use SFTP (with server validation - known hosts), or you may want to switch off server validation to get ...
The book teaches how to use freely available resources, such as PyGame Zero and Blender, to add animations, music, scrolling backgrounds, 3-D scenery, and other pieces of professional wizardry to ...
As well as focusing on client-side JavaScript, you will also learn how to work with the Browser Object Model, the Document Object Model (DOM), how to use XML and JSON as well as communicate with ...
3. How to use JD-GUI For example, to decompile "Object.class", you can : - execute the following command line : "jd-gui.exe Object.class". - select "Open File ..." in "File" menu and browse to "Object...
As well as focusing on client-side JavaScript, you will also learn how to work with the Browser Object Model, the Document Object Model (DOM), how to use XML and JSON as well as communicate with ...
Each recipe includes self-contained code solutions that you can freely use, along with a discussion of how and why they work. If you are familiar with Java basics, this cookbook will bolster your ...
paving the way for your students to explore how a commercial pipelined processor core works inside and to use this core in their projects, in effect creating their own SoC designs. With its long ...
3. How to use JD-GUI For example, to decompile "Object.class", you can : - execute the following command line : "jd-gui.exe Object.class". - select "Open File ..." in "File" menu and browse to "Object...
3. How to use JD-GUI For example, to decompile "Object.class", you can : - execute the following command line : "jd-gui.exe Object.class". - select "Open File ..." in "File" menu and browse to "Object...
how to use awk's built-in functions; how to write user-defined functions; debugging techniques for awk programs; how to develop an application that processes an index, demonstrating much of the power...
To use MATLAB freely, You just need to bring client exe file in you USB disk, whose size is only 2 megabytes. After clicking client exe file and inputing the IP address of server, you can input any ...
They use powerful techniques to process information intelligently and offer features based on patterns and relationships in data. Algorithms of the Intelligent Web shows readers how to use the same ...
该方法具有一个输入参数 `EXPORTING value_help_listener TYPE REF TO IF_WD_VALUE_HELP_LISTENER`。在这个方法中,设置监听器实例,这样当用户在父组件中请求值帮助时,这个监听器就会被触发。 3. **处理数据获取*...
A unique feature of the book is that it explains how to acquire, install, and use freely available software to edit, compile, and run console programs on just about any system, including Windows and ...
The author also shows how to use pre-existing legacy code (usually in Fortran77) within the Python environment, thus avoiding the need to master the original code. In this new edition, several ...
// // Distribute and change freely, except: don't remove my ...// How to use: // Instead of calling the API directly, // OpenThemeData(...); // use the global variable // g_xpStyle.OpenThemeData(...);