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

📄 messagemidlet.java

📁 这是郭克华老师的J2ME视频的源代码
💻 JAVA
字号:
package prj7_1;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class MessageMIDlet extends MIDlet implements CommandListener,ItemStateListener{
	private Display dis;
	/******************欢迎界面**********************/
	private Form welcomeForm = new Form("欢迎界面");
	private ImageItem welcomeItem;
	private Command cmdExit = new Command("退出程序",Command.EXIT,1);
	private Command cmdWriteMsg = new Command("写短信",Command.SCREEN,1);
	/******************短信编辑界面*******************/
	private Form frmMsg = new Form("请您输入短信");
	private TextField tfMsg = new TextField("","",255,TextField.ANY);
	private Command cmdMsgBack = new Command("返回",Command.BACK,1);
	private Command cmdMsgDel = new Command("清除文本",Command.BACK,1);	
	private Command cmdSend = new Command("发送",Command.SCREEN,1);
	/******************发送界面**********************/
	private TextBox tbPhone = new TextBox("请您输入对方号码","",15,TextField.NUMERIC);
	private Command cmdPhoneBack = new Command("返回",Command.BACK,1);
	private Command cmdOK = new Command("确定",Command.SCREEN,1);	
	
	public MessageMIDlet() {
		/******************欢迎界面初始化**********************/
		Image welcomeImg = null;
		try{
			welcomeImg = Image.createImage("/welcome.png");
		}catch(Exception ex){
			ex.printStackTrace();
		}
		welcomeItem = new ImageItem("欢迎您的到来",welcomeImg,Item.LAYOUT_CENTER,"");
		
		
	}
	protected void startApp() throws MIDletStateChangeException {
		dis = Display.getDisplay(this);
		dis.setCurrent(welcomeForm);
		/******************欢迎界面初始化**********************/
		welcomeForm.append(welcomeItem);
		welcomeForm.addCommand(cmdExit);
		welcomeForm.addCommand(cmdWriteMsg);
		/******************短信编辑界面初始化*******************/
		frmMsg.append(tfMsg);
		frmMsg.addCommand(cmdMsgBack);
		frmMsg.addCommand(cmdSend);
		/******************发送界面初始化**********************/
		tbPhone.addCommand(cmdPhoneBack);
		tbPhone.addCommand(cmdOK);
		/******************事件绑定代码***********************/
		welcomeForm.setCommandListener(this);
		frmMsg.setCommandListener(this);
		tbPhone.setCommandListener(this);
		frmMsg.setItemStateListener(this);//Item状态事件
	}
	public void commandAction(Command c,Displayable d){
		if(c==cmdExit){
			this.notifyDestroyed();
		}
		else if(c==cmdWriteMsg){
			dis.setCurrent(frmMsg);
		}
		else if(c==cmdMsgBack){
			dis.setCurrent(welcomeForm);
		}
		else if(c==cmdMsgDel){
			int position = tfMsg.getCaretPosition();
			tfMsg.delete(position-1, 1);
			if(tfMsg.size()==0){
				frmMsg.removeCommand(cmdMsgDel);
				frmMsg.addCommand(cmdMsgBack);
			}
		}
		else if(c==cmdSend){
			dis.setCurrent(tbPhone);			
		}
		else if(c==cmdPhoneBack){
			dis.setCurrent(frmMsg);
		}
		else if(c==cmdOK){
			System.out.println("短信成功发出");
			System.out.println("短信内容:"+tfMsg.getString());
			System.out.println("短信发送目的地"+tbPhone.getString());
		}
		
	}
	public void itemStateChanged(Item item) {
		if(item==tfMsg){
			if(tfMsg.size()!=0){
				frmMsg.removeCommand(cmdMsgBack);
				frmMsg.addCommand(cmdMsgDel);
			}
		}
	}
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}



}

⌨️ 快捷键说明

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