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

📄 prototype2.java

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

import java.io.IOException;

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 com.viacube.j2me.util.ImageUtil;

import mwt.Button;
import mwt.Component;
import mwt.EventListener;
import mwt.Label;
import mwt.Skin;
import mwt.Window;

public class Prototype2 extends MIDlet {

	public Prototype2() {

	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
	}

	protected void pauseApp() {
	}

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

}

class Canvas2 extends Canvas implements Runnable, EventListener {
	int width = getWidth();
	int height = getHeight();
	int w = 60;
	int h = 60;
	int Xhorizontal = 0;
	int Yvertical = 0;
	int Xinterval = 10;
	int Yinterval = 10;
	boolean exit;
	int Xrow = width / (Xinterval*2 + w);
	int Yrow = (height - 60) / (Yinterval*2 + h);
	Window win = new Window(0, 0, width, height);
	Window sub = new Window(0, height - 60, width, 60);
	Image image = null;
	Image img = null;
	Label label = null;
	boolean isPaint;
	int x[] = new int[2];
	int y[] = new int[2];
	protected void keyPressed(int keyCode){
		win.setKeyState(keyCode, Window.KEYSTATE_PRESSED, true);
	}
	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 Canvas2() {
		try {
			image = Image.createImage("/ken.png");
			img = new ImageUtil().zoomImage(image, w, h);
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		Image[] imgData = new Image[]{image};
//		int imgData[] = new int[img.getWidth()*img.getHeight()];
//		img.getRGB(imgData, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
		int color[] = new int[]{0xffedab};
//		Button.setDefaultSkin(Button.STYLE_DEFAULT, new Skin(imgData,60));
//		Button.setDefaultSkin(Button.STYLE_FOCUSED, new Skin(imgData,120));
//		Button.setDefaultSkin(Button.STYLE_PRESSED, new Skin(imgData,60));
//		Button.setDefaultSkin(Button.STYLE_DISABLED, new Skin(imgData,60));
		Button button = new Button(60,100,60,60,"show me!",this,0);
		Button button2 = new Button(130,100,60,60,"show !",this,0);
		button.setTextAlign(Button.ALIGN_BOTTOM_CENTER);
		Xinterval = (width - Xrow * w) / (Xrow + 1);
		Yinterval = (height - 60 - Yrow * h) / (Yrow + 1);
//		for ( int i = 0 ; i < Xrow ; i++) {
//			Xhorizontal = Xinterval + (Xhorizontal + Xinterval + w)*i;
//			for ( int j = 0 ; j < Yrow ; j++) {
//				Yvertical = Yinterval + (Yvertical + Yinterval + h)*j;
//				label = new Label(Xhorizontal, Yvertical, img);
//				win.add(label);
//			}
//		}
		
//		Xhorizontal = Xhorizontal + Xinterval + w;
//		Yvertical = Yvertical + Yinterval + h;
//		label = new Label(Xhorizontal, Yvertical, img);
//		win.add(label);
		win.add(button);
//		win.add(sub);
		
		
		win.add(button2);
		win.setFocusFirst();
		for(int i=0;i<2;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();
//				}
			}
		}
	}

	protected void paint(Graphics g) {
		g.setColor(-1);
		g.fillRect(0, 0, width, height);
		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 run() {
		while(!exit){
			win.repeatKeys(true);
			repaint();
			serviceRepaints();
		}
	}

	public void processEvent(int eventType, Component c, Object[] args) {

	}

}

⌨️ 快捷键说明

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