📄 example12.java
字号:
package example;
/*
* MWT - Micro Window Toolkit
* Copyright (C) 2007 Lucas Domanico - lucazd@gmail.com
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://j2me-mwt.sourceforge.net/
*/
import java.util.Random;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import mwt.Button;
import mwt.Component;
import mwt.EventListener;
import mwt.Font;
import mwt.Label;
import mwt.Window;
// Custom Fonts
//
class Canvas12 extends Canvas implements Runnable, EventListener {
Window win = new Window(4,4,120,120); // the main window -reference-
boolean exit; // setted to true to finish the application
static final int ACTION_EXIT = 0; // button's action ids
static final int ACTION_CHANGECOLOR = 1;
Font[] font = new Font[2];
int currentFont;
// notify input
protected void keyPressed(int keyCode) { win.setKeyState(keyCode,Window.KEYSTATE_PRESSED,true); }
protected void keyReleased(int keyCode) { win.setKeyState(keyCode,Window.KEYSTATE_RELEASED,true); }
// event listener implementation
public void processEvent(int eventType, Component sender, Object[] args) {
switch(eventType) {
case EVENT_ACTION: // when a button is pressed an event action is triggered
switch(((Button)sender).getActionType()) {
case ACTION_CHANGECOLOR:
currentFont = (currentFont == 0)? 1 : 0;
Component panel = win.getChild(2);
for(int i=0; i<panel.getChildCount() ;i++)
((Label)panel.getChild(i)).setFont(Label.STYLE_DEFAULT,font[currentFont]);
return;
case ACTION_EXIT: exit = true; return;
}
break;
default: break;
}
}
Canvas12() {
try {
final char[] charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'".toCharArray();
final Image[] images1 = new Image[charset.length];
final Image[] images2 = new Image[charset.length];
for(int i=0; i<charset.length ;i++) {
images1[i] = Image.createImage("/font1/" + ((int)charset[i]) + ".png");
images2[i] = Image.createImage("/font2/" + ((int)charset[i]) + ".png");
}
font[0] = new Font(images1, charset, -3);
font[1] = new Font(images2, charset, -3);
}
catch(Exception e) { e.printStackTrace(); }
Button.setDefaultFont(Button.STYLE_DEFAULT, font[0]);
Button.setDefaultFont(Button.STYLE_FOCUSED, font[1]);
Button.setDefaultFont(Button.STYLE_PRESSED, font[0]);
win.add(new Button(6,82,50,24,"Color",this,ACTION_CHANGECOLOR));
win.add(new Button(64,82,50,24,"Exit",this,ACTION_EXIT));
Window panel = new Window(6,6,108,70);
Label.setDefaultFont(Label.STYLE_DEFAULT, font[0]);
panel.add(new Label(8, 4,100,30,"Use your own"));
panel.add(new Label(8,20,100,30,"custom fonts"));
panel.add(new Label(8,36,100,30,"to improve your"));
panel.add(new Label(8,52,100,30,"application look"));
win.add(panel);
win.setFocusFirst();
}
protected void paint(Graphics g) {
g.setColor(0xFFFFFFFF);
g.fillRect(0,0,getWidth(),getHeight());
Random r = new Random();
for(int i=0; i<10 ;i++) {
g.setColor(Math.abs(r.nextInt()));
g.drawRect(Math.abs(r.nextInt())%128,Math.abs(r.nextInt())%128,Math.abs(r.nextInt())%128,Math.abs(r.nextInt())%128);
}
win.paint(g);
}
public void run() {
while(!exit) {
win.repeatKeys(true);
repaint();
serviceRepaints();
try { Thread.sleep(1); }
catch(Exception e) { e.printStackTrace(); }
}
Example12.instance.notifyDestroyed();
}
}
public class Example12 extends MIDlet {
static MIDlet instance;
static Canvas canvas;
protected void startApp() throws MIDletStateChangeException {
instance = this;
Canvas12 c = new Canvas12();
canvas = c;
Display.getDisplay(this).setCurrent(c);
new Thread(c).start();
}
protected void pauseApp() { }
protected void destroyApp(boolean arg0) throws MIDletStateChangeException { }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -