www.pudn.com > 手机网游源码.rar > Msg.java


package com.dfun.blackjack; 
 
import javax.microedition.lcdui.*; 
import java.util.Vector; 
 
/************************************************** 
 * @author Beetle 
 * 类功能介绍: 
 **************************************************/ 
public class  Msg implements CommandListener { 
	private Main main; 
	private Display display; 
	private Connection conn; 
	private TextField myMsg; 
	private Form msgForm; 
	private Command send; 
	private Command back; 
	private Displayable tempDisplay; 
	/******************************************************* 
	 * 功能介绍:构造函数 
	 * 输入参数:无 
	 *******************************************************/ 
	public Msg(Main main, Display display,Connection conn) { 
		this.main = main; 
		this.display = display; 
		this.conn=conn; 
		send = new Command("发送", Command.OK, 1); 
		back = new Command("返回", Command.BACK, 1); 
		msgForm = new Form("聊天室"); 
		myMsg = new TextField(null, "", 20, TextField.ANY); 
		msgForm.addCommand(send); 
		msgForm.addCommand(back); 
		msgForm.append(myMsg); 
		msgForm.setCommandListener(this); 
	} 
 
	public void commandAction( Command c,Displayable d) { 
		if (c == send ) { 
			String strTmp=myMsg.getString(); 
			if (strTmp.length()==0){ 
				return; 
			} 
			conn.sendOneData("13"+main.strUserName+"说: "+ strTmp); 
			myMsg.setString(""); 
		} 
		else if (c == back) { 
			display.setCurrent(tempDisplay); 
		} 
	} 
 
	public void showForm() { 
		tempDisplay = display.getCurrent(); 
		display.setCurrent(msgForm); 
	} 
 
	public void addMsg(String strTmp){ 
		msgForm.append(strTmp+"\n"); 
		if(msgForm.size() > 6){ 
			msgForm.delete(1); 
		} 
		if (display.getCurrent()==msgForm){ 
			display.setCurrent(msgForm); 
		} 
	} 
}