?? example13.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 Canvas13 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;
}
}
Canvas13() {
try {
int[] widths = { 10, 11, 11, 11, 10, 9, 10, 10, 6, 11, 11, 9, 14, 10, 11, 11, 10, 10, 11, 10, 10, 10, 14, 10, 9, 10, 9, 10, 10, 11, 10, 8, 11, 10, 6, 8, 10, 6, 11, 10, 9, 10, 10, 7, 10, 6, 10, 9, 11, 9, 10, 10, 11, 8, 11, 10, 10, 10, 11, 9, 10, 10, 5 };
char[] charset = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\'' };
final Image images1 = Image.createImage("/mwt.png");
final Image images2 = Image.createImage("/mwt.png");
font[0] = new Font(images1, charset, widths, -3);
font[1] = new Font(images2, charset, widths, -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(); }
}
Example13.instance.notifyDestroyed();
}
}
public class Example13 extends MIDlet {
static MIDlet instance;
static Canvas canvas;
protected void startApp() throws MIDletStateChangeException {
instance = this;
Canvas13 c = new Canvas13();
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 + -