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

📄 example11.java

📁 Micro Window Toolkit(MWT)是一个用于开发J2ME用户界面(UI)的工具包。它具有友好
💻 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.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 Canvas11 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;
		}
	}
	
	Canvas11() {
		try {
			font[0] = new Font(getClass().getResourceAsStream("/mwt.mf"),null,-2,16,0xFFFFFF);
			font[1] = new Font(getClass().getResourceAsStream("/mwt.mf"),null,-2,16,0xCFFF40);
		}
		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(); }
		}
		Example11.instance.notifyDestroyed();
	}
}


public class Example11 extends MIDlet {
	static MIDlet instance;
	static Canvas canvas;
	protected void startApp() throws MIDletStateChangeException {
		instance = this;
		Canvas11 c = new Canvas11();
		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 + -