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

📄 prototype4.java

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

import java.util.Vector;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
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;

public class Prototype4 extends MIDlet {
	static MIDlet instance;
	static Canvas canvas;
	public Prototype4() {
		instance = this;
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}

	protected void pauseApp() {}

	protected void startApp() throws MIDletStateChangeException {
		Canvas4 c = new Canvas4 ();
		canvas = c;
		Display.getDisplay(this).setCurrent(c);
		new Thread(c).start();
	}
}

class Canvas4 extends Canvas implements Runnable, EventListener{

	private boolean exit = false;	
	private Window win = new Window(0,0,getWidth(),getHeight()){
		private final int FOCUSEACTION_LEFT = 91;
		private final int FOCUSEACTION_RIGHT = 92;
		
		public int getFocusAction(long key) {
			System.out.println("Frank : key=" + key);
			switch((int) key) {
				case Canvas.LEFT: return FOCUSEACTION_LEFT;
				case Canvas.RIGHT: return FOCUSEACTION_RIGHT;
				case Canvas.UP: return FOCUSACTION_PREV;
				case Canvas.DOWN: return FOCUSACTION_NEXT;
				case Canvas.KEY_NUM5: return FOCUSACTION_FIRE;
				default: return FOCUSACTION_NONE;
				}
		}
		protected void dispatchKey(long key) {
			super.dispatchKey(key);
			switch ( (int)key) {
				case FOCUSEACTION_RIGHT : System.out.println("RIGHT!"); break;
				case FOCUSEACTION_LEFT : System.out.println("LEFT"); break;
			}
		}
	};
	
	public Canvas4() {
//		Label la = new Label(0, 0, 60, 20, false);
//		la.setBgColor(0xffeedd);
//		la.setFontColor(0xa12abc);
//		la.setText("This is a Label");
//		la.setVisible(true);
//		la.setTextAlign(0);
//		win.add(la);
		win.add(new Button(5, 5, 100, 100, "Hello! World.", this, 100));
		win.setFocusFirst();
	}
	protected void keyPressed(int keyCode){
		win.setKeyState(keyCode, Window.KEYSTATE_PRESSED, true);
	}
	
	protected void paint(Graphics g) {
		win.paint(g);		
	}

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

	public void processEvent(int eventType, Component c, Object[] args) {
		System.out.println("Frank here!");
	}
}

⌨️ 快捷键说明

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