⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prototype1.java

📁 Micro Window Toolkit(MWT)是一个用于开发J2ME用户界面(UI)的工具包。它具有友好
💻 JAVA
字号:
package prototype;

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.Skin;
import mwt.Window;

class CanvasPrototype1 extends Canvas implements Runnable, EventListener {
	Window win = new Window(0,0,getWidth(),getHeight());
	boolean exit;
	final static int ACTION_ALERT = 0;
	final static int ACTION_CLOSEDIALOG = 1;
	final static int ACTION_SUB = 2;
	int[] color ={0x87CEEB};
	int width = getWidth();
	int height = getHeight();
	boolean isPaint;
	int[] x = new int[16];
	int[] y = new int[16];
	
	protected void keyPressed(int keyCode){
		win.setKeyState(keyCode, Window.KEYSTATE_PRESSED, true);
		if(keyCode == Canvas.KEY_NUM0)exit = true;return;
	}
	
	protected void keyReleased(int keyCode){
		win.setKeyState(keyCode, Window.KEYSTATE_RELEASED, true);
		if(win.getFocusAction(keyCode)==Window.FOCUSACTION_NEXT||win.getFocusAction(keyCode)==Window.FOCUSACTION_PREV||win.getFocusAction(keyCode)==Window.FOCUSACTION_NONE){
			isPaint = false;
			}
	}

	public CanvasPrototype1() {
		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', '\'' };
			Image image = Image.createImage("/mwt.png");
			Font font = new Font(image,charset,widths,-3);
			Button.setDefaultFont(Button.STYLE_DEFAULT, font);
			Button.setDefaultFont(Button.STYLE_FOCUSED, font);
//			Button.setDefaultFont(Button.STYLE_PRESSED, font);
			Button.setDefaultFont(Button.STYLE_DISABLED, font);
			
//			Button.setDefaultSkin(Button.STYLE_DEFAULT, new Skin(color));
//			Button.setDefaultSkin(Button.STYLE_PRESSED, new Skin(color));
//			Button.setDefaultSkin(Button.STYLE_DISABLED, new Skin(color));
//			Button.setDefaultSkin(Button.STYLE_FOCUSED, new Skin(color));
			Label.setDefaultFont(Label.STYLE_DEFAULT, font);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		win.add(new Button(10, 15, (width-60)/4,(height-110)/4,"ONE",this,ACTION_SUB));
		win.add(new Button((width-30)/4+15, 15, (width-60)/4,(height-110)/4,"TWO",this,ACTION_ALERT));
		win.add(new Button((width-30)/2+20, 15,(width-60)/4,(height-110)/4,"THREE",this,ACTION_ALERT));
		win.add(new Button((width-30)*3/4+25, 15, (width-60)/4,(height-110)/4,"FOUR",this,ACTION_ALERT));
		win.add(new Button(10,(height-30)/4+20, (width-60)/4, (height-110)/4,"FIVE",this,ACTION_ALERT));
		win.add(new Button((width-30)/4+15, (height-30)/4+20, (width-60)/4,(height-110)/4,"SIX",this,ACTION_ALERT));
		win.add(new Button((width-30)/2+20, (height-30)/4+20, (width-60)/4,(height-110)/4,"SEVEN",this,ACTION_ALERT));
		win.add(new Button((width-30)*3/4+25, (height-30)/4+20, (width-60)/4,(height-110)/4,"EIGHT",this,ACTION_ALERT));
		win.add(new Button(10,(height-30)/2+25, (width-60)/4, (height-110)/4,"NINE",this,ACTION_ALERT));
		win.add(new Button((width-30)/4+15, (height-30)/2+25, (width-60)/4,(height-110)/4,"TEN",this,ACTION_ALERT));
		win.add(new Button((width-30)/2+20, (height-30)/2+25, (width-60)/4,(height-110)/4,"ELEVEN",this,ACTION_ALERT));
		win.add(new Button((width-30)*3/4+25, (height-30)/2+25, (width-60)/4,(height-110)/4,"TWELVE",this,ACTION_ALERT));
		
		Window sub = new Window(0,(3*height)/4,width,(height+5)/4);
		sub.add(new Button(10,15,(width-60)/4,(height-110)/4,"THREE",this,ACTION_ALERT));
		sub.add(new Button((width-30)/4+15,15,(width-60)/4,(height-110)/4,"THREE",this,ACTION_ALERT));
		sub.add(new Button((width-30)/2+20,15,(width-60)/4,(height-110)/4,"THREE",this,ACTION_ALERT));
		sub.add(new Button((width-30)*3/4+25,15,(width-60)/4,(height-110)/4,"THREE",this,ACTION_ALERT));
		sub.setFocusFirst();
		sub.setSkin(Window.STYLE_DEFAULT, new Skin(color));
		win.add(sub);
		win.setFocusFirst();
		for(int i=0;i<13;i++){
			Component c = win.getChild(i);
			if(c instanceof Button){
				x[i]= c.getX();
				y[i]=c.getY();
			}else{
				for(int j=0;j<4;j++){
					Component co = c.getChild(j);
					x[i+j] = co.getX();
					y[i+j] = co.getY();
				}
			}
		}
	}

	public void run() {
		while(!exit){
			win.repeatKeys(true);
			repaint();
			serviceRepaints();
		}
		Prototype1.instance.notifyDestroyed();
	}

	protected void paint(Graphics g) {
		g.setColor(-1);
		g.fillRect(0, 0, getWidth(), getHeight());
		if(!isPaint){
			isPaint = true;
			for(int i=0;i<win.getChildCount();i++){
				Component c = win.getChild(i);
				if(c instanceof Button){
					if(win.getFocus()==c){
//					((Button)c).setSkin(Button.STYLE_DEFAULT, new Skin(color));
						c.setWidth((width-20)/4);
						c.setHeight((height-55)/4);
						
						c.setX(x[win.getChild(c)]-5);
						c.setY(y[win.getChild(c)]-5);
						System.out.println("x= "+win.getChild(c));
					}else{
						((Button)c).setSkin(Button.STYLE_DEFAULT, Button.getDefaultSkin(Button.STYLE_PRESSED));
						c.setWidth((width-60)/4);
						c.setHeight((height-110)/4);
						c.setX(x[win.getChild(c)]);
						c.setY(y[win.getChild(c)]);
						
					}
				}else{
					for(int j=0;j<c.getChildCount();j++){
						Component co = c.getChild(j);
						if(win.getFocus()==co){
							co.setWidth((width-20)/4);
							co.setHeight((height-55)/4);
							co.setX(x[12+c.getChild(co)]-5);
							co.setY(y[12+c.getChild(co)]-8);
						}else{
							co.setWidth((width-60)/4);
							co.setHeight((height-110)/4);
							co.setX(x[12+c.getChild(co)]);
							co.setY(y[12+c.getChild(co)]);
						}
					}
				}
			}
		}
		win.paint(g);
	}

	public void processEvent(int eventType, Component c, Object[] args) {
		switch(eventType){
			case EVENT_ACTION:
				switch(((Button)c).getActionType()){
					case ACTION_ALERT:
						final Window dialog = new Window(60,60,80,90);
						dialog.add(new Label(10,20,40,20,"Confirm"));
						dialog.add(new Button(20,50,40,20,"return",this,ACTION_CLOSEDIALOG));
						dialog.setFocusFirst();
						win.dialogOpen(dialog);
						break;
					case ACTION_CLOSEDIALOG:
						win.dialogClose();break;
					case ACTION_SUB:
				}
				break;
			default:break;
		}
	}

}

public class Prototype1 extends MIDlet {
	static MIDlet instance;
	public Prototype1() {
		instance = this;
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}
	protected void pauseApp() {}

	protected void startApp() throws MIDletStateChangeException {
		CanvasPrototype1 cp = new CanvasPrototype1();
		Display.getDisplay(this).setCurrent(cp);
		new Thread(cp).start();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -