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

📄 dialog.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 java.util.TimerTask;

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

import org.wuhua.wap.log.Logger;
import org.wuhua.wap.ui.Command;
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.timer.TimerTaskManager;

 

/**
 * <b>类名:Dialog.java</b> </br> 编写日期: 2006-9-16 <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 Dialog extends Canvas implements Runnable {
	private static Logger logger = Logger.getLogger("Dialog");

	protected final int X = 0;

	protected final int Y = 1;

	protected	final int WIDTH = 2;

	protected final int HEIGHT = 3;

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

	/** Preset alternative containing OK */
	public static final int DIALOG_OK = 0;

	/** Preset alternative containing CANCEL = 1 */
	public static final int DIALOG_CANCEL = 2;

	/** Preset alternatives containing YES and NO */
	public static final int DIALOG_YES_NO = 3;

	/** Preset alternatives containing OK and CANCEL */
	public static final int DIALOG_OK_CANCEL = 4;

	/** Preset alternatives containing YES, NO, and CANCEL */
	public static final int DIALOG_YES_NO_CANCEL = 5;

	public static final int DIALOG_TEXT = 6;

	/**
	 * 保存当前窗口,主要用途是,当前对话筐消失的时候,要求重绘制. 永远刷新父类
	 */
	protected Panel parent;

	protected boolean hasFocus;

	/**
	 * 定义超时参数
	 */
	long timeOut;

	/**
	 * 对话框类型
	 */
	int type;

	/** 对话框标题 */
	protected String title;

	/**
	 * 把单行标题转换为多行以方便显示
	 */
	protected	String[] rowTitle;

	protected int bgColor;

	protected int fontColor;

	protected Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
				Font.SIZE_SMALL);

	/** 用于执行消失窗口 */
	protected TimerTask task;

	protected Display display;

	protected SoftButton softButton;
	
 
 
	
	
	/**
	 * 构造一个默认的标题,父类的窗口
	 * 
	 * @param title
	 * @param parent
	 */
	public Dialog(String title, Panel parent, Display display) {
		this(title, parent, display, 3000);
	}

	/**
	 * 构造一个指定时间的构造窗口
	 * 
	 * @param title
	 * @param parent
	 * @param timeOut
	 */
	public Dialog(String title, Panel parent, Display display, long timeOut) {
		this(title, parent, display, Dialog.DIALOG_OK, timeOut);
	}

	/**
	 * 构造一个指定窗口类型,时间的窗口
	 * 
	 * @param title
	 * @param parent
	 * @param type
	 * @param timeOut
	 */
	public Dialog(String title, Panel parent, Display display, int type,
			long timeOut) {
 		setFullScreenMode(true);
		
		this.parent = parent;
	    checkParent();
		
		this.timeOut = timeOut;
		this.type = type;
		this.title = title;
		this.display = display;
		
		softButton = new SoftButton();
		
		initWidthAndHeight();
		
		if (timeOut != 0)
			task = TimerTaskManager.getInstace().add(this, timeOut); 
		
		//设置默认的风格
		setStyle(0x0033FF, 0xFFFFFF);
		
	}

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

	public void cancel() {
	 
		if (parent == null)
			throw new NullPointerException("Parent is not Null.");
		
		task.cancel();
		if(parent == null)
			return;
		
		display.setCurrent(parent);
		 
	}

	public void addCommand(Command cmd) {
		this.softButton.addCommand(cmd);
	}

	public void setSoftButtonListener(CommandListener cml) {
		this.softButton.setCommandListener(cml);
	}
	
	public final void setTitle(String title) {
		this.title = title;
	}

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

	public void run() {
		cancel();

	}

	/** 绘制透明色 * */
   public	void drawRGB(Graphics g) {
		int ai[] = new int[Platform.WIDTH];
		for (int j1 = 0; j1 < ai.length; j1++)
			ai[j1] = 0x90000000;
		g.drawRGB(ai, 0, 0, 0, 0, Platform.WIDTH, Platform.HEIGHT, true); // 绘制透明景色
	}

	protected final void sizeChanged(int w, int h) {
		if (h > Platform.HEIGHT) {
			Platform.WIDTH = w;
			Platform.HEIGHT = h;

		}
	}
	
	/**
	 * 如果程序因为这个而改变的话,那我就顶你的拉
	 *
	 */
	private void initWidthAndHeight() {
		if (Platform.HEIGHT < this.getHeight()) {	 
			Platform.WIDTH = this.getWidth();
			Platform.HEIGHT = this.getHeight();
		}
	}


	private void checkParent() {
		if (parent == null){
			 throw new NullPointerException("Parent is not null");
		}
			
	}

	protected void keyPressed(int keyCode) {
		softButton.onClick(keyCode);
		
	}

	public void setPanel(Panel panel) {
		this.parent = panel;
		
	}

	public void setTimeOut(long timeOut) {
		this.timeOut = timeOut;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

}

⌨️ 快捷键说明

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