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

📄 component.java

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

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


public abstract class Component implements Focusable {

	/** Constant for component/text alignment. */
	static final public int ALIGN_TOP_LEFT = 0;

	static final public int ALIGN_TOP_CENTER = Graphics.TOP | Graphics.HCENTER;

	static final public int ALIGN_TOP_RIGHT = Graphics.TOP | Graphics.RIGHT;

	static final public int ALIGN_MIDDLE_LEFT = Graphics.VCENTER
			| Graphics.LEFT;

	static final public int ALIGN_MIDDLE_CENTER = Graphics.VCENTER
			| Graphics.HCENTER;

	static final public int ALIGN_MIDDLE_RIGHT = Graphics.VCENTER
			| Graphics.RIGHT;

	static final public int ALIGN_BOTTOM_LEFT = Graphics.BOTTOM | Graphics.LEFT;

	static final public int ALIGN_BOTTOM_CENTER = Graphics.BOTTOM
			| Graphics.HCENTER;

	static final public int ALIGN_BOTTOM_RIGHT = Graphics.BOTTOM
			| Graphics.RIGHT;

	private boolean enabled = true;

	private boolean visible = true;

	private int x;

	private int y;

	private int width;

	private int height;

	int skinWidth;

	int skinHeight;

	Image skinImage;
	
	private  Skin[] skins;

	private Component parent;

	private boolean focusable;

	private boolean isContainer;

	Component(int x, int y, int width, int height) {
		this.setX(x);
		this.setY(y);
		this.setWidth(width);
		this.setHeight(height);
		this.focusable = true;
		this.isContainer = false;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	/** Gets the width of this component */
	public int getWidth() {
		return width;
	}

	public Focusable getParent() {
		return parent;
	}

	public void setParent(Component parent) {
		this.parent = parent;
	}

	/** Sets the width of this component */
	public void setWidth(int width) {
		this.width = width;
	}

	/** Gets the height of this component */
	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public Skin getSkin(int style) {
		return skins[style];
	}

	/** Sets the skin for the given style. */
	public void setSkin(int style, Skin skin) {
		skins[style] = skin;
	}
	
	public boolean isVisible() {
		return visible;
	}

	/** Shows or hides this component */
	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public boolean isFocusable() {
		return focusable;
	}

	/**
	 * Enables or disables focusable.
	 * 
	 */
	public void setFocusable(boolean focusStop) {
		this.focusable = focusStop;
	}

	public boolean isContainer() {
		return isContainer;
	}

	/**
	 * base event of the key,return true if the component processs the event.
	 * 
	 * @param key
	 *            the KeyCode of the phone
	 * @return return true if the component processs the event.
	 */
	protected boolean keyEvent(long key) {
		return false;
	}

	/* (non-Javadoc)
	 * @see com.opusmicro.ui.Focusable#focusGained()
	 */
	public  void focusGained() {
	}

	/* (non-Javadoc)
	 * @see com.opusmicro.ui.Focusable#focusLost()
	 */
	public  void focusLost() {
	}

	/* (non-Javadoc)
	 * @see com.opusmicro.ui.Focusable#acceptsFocus()
	 */
	public boolean acceptsFocus() {
		for (Component cursor = this; cursor != null; cursor = cursor.parent)
			if (!cursor.visible || !cursor.enabled)
				return false;
		return true;
	}

	final public boolean isHierarchyEnabled() {
		for (Component cursor = this; cursor != null; cursor = cursor.parent)
			if (!cursor.enabled)
				return false;
		return true;
	}
	
	protected void paint(Graphics g) {
		for (int i = 0; i < skins.length; i++) {
			getSkin(i).paint(this, g);
		}	
		paintImpl(g);
	}
	
	/**
	 * called by the subclass to paint
	 * @param g
	 * @param w
	 */
	protected void paintImpl(Graphics g){
		
	}
	
	

}

⌨️ 快捷键说明

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