📄 fontseffectsmidlet.java
字号:
/***************************************************************************** Description: A midlet with a canvas displaying system text with effects. Created By: Oscar Vivall @file FontsEffectsMIDlet.java COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2004. The software is the copyrighted work of Sony Ericsson Mobile Communications AB. The use of the software is subject to the terms of the end-user license agreement which accompanies or is included with the software. The software is provided "as is" and Sony Ericsson specifically disclaim any warranty or condition whatsoever regarding merchantability or fitness for a specific purpose, title or non-infringement. No warranty of any kind is made in relation to the condition, suitability, availability, accuracy, reliability, merchantability and/or non-infringement of the software provided herein.*****************************************************************************/import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class FontsEffectsMIDlet extends javax.microedition.midlet.MIDlet { private MIDlet midlet = this; public void startApp() { Display.getDisplay(this).setCurrent(new FontCanvas()); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public class FontCanvas extends Canvas{ private final int WIDTH, HEIGHT; private int effect = 0; private FontEffect fontEffect1, fontEffect2, fontEffect3, fontEffect4, fontEffect5; int colorIndex = 0; int []color = new int[] {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF}; public FontCanvas(){ setFullScreenMode(true); WIDTH = getWidth(); HEIGHT = getHeight(); fontEffect1 = new FontEffect("Hello World!"); fontEffect1.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); fontEffect2 = new FontEffect("Hello World!"); fontEffect2.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); fontEffect2.applyEffect(FontEffect.EFFECT_COLOR); colorIndex = colorIndex<color.length-1?colorIndex+1:0; fontEffect2.setColor(color[colorIndex]); fontEffect3 = new FontEffect("Hello World!"); fontEffect3.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); fontEffect3.applyEffect(FontEffect.EFFECT_MASK | FontEffect.EFFECT_COLOR); fontEffect4 = new FontEffect("Hello World!"); fontEffect4.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); fontEffect4.applyEffect(FontEffect.EFFECT_MONOSPACE | FontEffect.EFFECT_COLOR); fontEffect5 = new FontEffect("Hello World!"); fontEffect5.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); colorIndex+=2; fontEffect5.setColor(color[colorIndex]); fontEffect5.applyEffect(FontEffect.EFFECT_MONOSPACE | FontEffect.EFFECT_MASK | FontEffect.EFFECT_COLOR); } public void paint(Graphics g) { g.setColor(0xFF0000); g.fillRect(0, 0, WIDTH, HEIGHT); fontEffect1.render(g, 5, 5, 0); fontEffect2.render(g, 5, 25, 0); fontEffect3.render(g, 5, 45, 0); fontEffect4.render(g, 5, 65, 0); fontEffect5.render(g, 5, 85, 0); g.setColor(0xFFFFFF); g.fillRect(0, HEIGHT, WIDTH, HEIGHT); g.setColor(0x00); g.drawString("Exit", 0, HEIGHT, Graphics.LEFT | Graphics.BOTTOM); g.drawString("Change Color", WIDTH, HEIGHT, Graphics.RIGHT | Graphics.BOTTOM); } public void keyPressed(int key){ switch(key){ case -6: midlet.notifyDestroyed(); break; case -7: colorIndex = colorIndex<color.length-1?colorIndex+1:0; fontEffect2.setColor(color[colorIndex]); fontEffect3.setColor(color[colorIndex]); fontEffect4.setColor(color[colorIndex]); fontEffect5.setColor(color[colorIndex]); break; case 49: break; case 50: break; } repaint(); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -