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

📄 panel.java

📁 j2me开发的1个简单的wap浏览器.程序框架还是不错的.包括对低级事件的处理.通信框架,标签的解析
💻 JAVA
字号:
/********************************************************************
 * 项目名称				:<b>j2me学习 J2me Wap Explorer</b>			<br/>
 * 
 * Copyright 2005-2006 Wuhua. All rights reserved </br>
 *
 * 本程序只用于学习目的,不能用于商业目的。如有需要请联系作者
 ********************************************************************/
package org.wuhua.wap.ui.form;

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

import org.wuhua.wap.log.Logger;
import org.wuhua.wap.ui.Command;
import org.wuhua.wap.ui.Part;
import org.wuhua.wap.ui.SoftButton;
import org.wuhua.wap.ui.core.Platform;
import org.wuhua.wap.ui.event.CommandListener;
import org.wuhua.wap.ui.event.PartChangeListener;

/**
 * <b>类名:Panel.java</b> </br> 编写日期: 2006-9-15 <br/> 程序功能描述: <br/> Demo: <br/>
 * Bug: <br/>
 * 
 * 程序变更日期 :<br/> 变更作者 :<br/> 变更说明 :<br/>
 * 
 * @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
 */
public abstract class Panel extends Canvas {
	private static Logger log = Logger.getLogger("Panel");

	final int X = 0;

	final int Y = 1;

	final int WIDTH = 2;

	final int HEIGHT = 3;

	/** 显示主要部分.比如菜单的Icon,List的数据的位置 */
	int[] viewContent = new int[4];

	Image icon;
	protected Part part;
	
	SoftButton softButton;
	
	Part schedule;
	int bgColor;
	int fontColor;
    
	Font font =  Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
			Font.SIZE_SMALL);
	public Panel(Image icon) {
		setFullScreenMode(true);
		initWidthAndHeight();
		initViewContent();
		this.icon = icon;
		this.softButton = new SoftButton();
		 
		//此方法是让所以的Panel都添加一个TimerPart
		//以后重构的时候应该考虑要不要这么做
		//this.setTimer(null);
	}

	public void addCommand(Command cmd) {
		if (cmd == null)
			return;
		softButton.addCommand(cmd);
	}

	
	public Part getPart() {
		return part;
	}

	public void append(Part part){
		this.part = part;
	}
	public void setPartChangeListener(PartChangeListener partChangeListener) {
		this.part.setPartChangeListener(partChangeListener);
	}

	public void removeCommand(Command cmd) {

		softButton.removeCommand(cmd);
	}

	public void setSoftButtonListener(CommandListener cmdListener) {
		if (softButton != null)
			softButton.setCommandListener(cmdListener);
	}

	public void setSoftButtonStyle(int bgColor, int fontColor){
		this.softButton.setStyle(bgColor, fontColor);
	}

	public abstract void paint(Graphics g);

	protected abstract void keyPressed(int keyCode);

	/**
	 * 长按事件
	 */
	protected void keyRepeated(int keyCode) {
		keyPressed(keyCode);
	}

	protected   void sizeChanged(int w, int h) {
		if (h > Platform.HEIGHT) {
			Platform.WIDTH = w;
			Platform.HEIGHT = h;
			initViewContent(); // 重新初始话,发现在nokia上需要调用此方法,才可以获得真正的高宽
		}
	}
	private void initWidthAndHeight() {
		if (Platform.HEIGHT < this.getHeight()) {	 
			Platform.WIDTH = this.getWidth();
			Platform.HEIGHT = this.getHeight();
		}
	}

	private void initViewContent() {
		viewContent[X] = 0;
		viewContent[Y] = 45;
		viewContent[WIDTH] = Platform.WIDTH;
		viewContent[HEIGHT] = Platform.HEIGHT;
	}

	public SoftButton getSoftButton() {
		return softButton;
	}

	public void setSoftButton(SoftButton softButton) {
		this.softButton = softButton;
	}
	
    
	void paintScheduleImpl(Graphics g){
		if(schedule != null)
			schedule.paint(g);
	}
	
	public void repaintSchedule(){
		if(schedule != null){
			int [] view = schedule.getView();
			repaint(view[X],view[Y],view[WIDTH], view[HEIGHT] );
		}
			
	}
	
	public void setStyle(int bgColor, int fontColor) {
		this.bgColor = bgColor;
		this.fontColor = fontColor;
	}

	public final void setSchedule(Part schedule) {
		this.schedule = schedule;
	}

	public final void setFont(Font font) {
		this.font = font;
	}


}

⌨️ 快捷键说明

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