addphotoform.java

来自「手机在线系统 采用Java 中的J2ME, JSP 跟MySql 运行环」· Java 代码 · 共 137 行

JAVA
137
字号
/**
 * @(#)AddPhotoForm.java	
 * Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
 * @version 	1.0, 10/05/2004
 * @author 	饶荣庆
 * @author 	
 */
package com.j2me.myphoto;

import com.j2me.main.*;	
import javax.microedition.lcdui.*;

/**
 *新增功能的类
 */
public class  AddPhotoForm extends Form implements CommandListener 
{
	private Display display = null;
	private PhotoBookMenu photoBookMenu = null;
	public static Alert addAlert = null;	//定义为静态是为了利于修改属性
	public static Alert modifyAlert = null; 
	public static Alert infoAlert = new Alert(null, null, null, AlertType.INFO); 	 //动态的改变语言 
	public static TextField idTextField= null;
	public static TextField nameTextField= null;
	public static TextField pathTextField= null;
	public Command okCommand = null;			//定义确定软键
	public Command backCommand = null;			//定义离开软键
	public Command confirmCommand = null;			//定义确定软键
	public Command cancelCommand = null;			//定义取消软键
	private PhotoBook pb = null;
	private int _id ;
	private	String _name;
	private	String _path;
	private	int recordID;
	private boolean isAdd = true;

	public AddPhotoForm(String s)
	{
		super(s);
		this.addAlert = new Alert("提示", "添加成功", null, AlertType.INFO);	 //初始化信息
		this.addAlert.setTimeout(1000);
		this.modifyAlert = new Alert("提示", "这条记录已经存在!是否对它进行修改!", null, AlertType.INFO);	 //初始化信息
		this.modifyAlert.setTimeout(1000);
		this.infoAlert.setTimeout(1000);
		this.okCommand = new Command("确定", Command.OK, 2);	
		this.backCommand = new Command("返回", Command.BACK, 2);
		this.confirmCommand = new Command("确定", Command.OK, 2);	
		this.cancelCommand = new Command("取消", Command.BACK, 2);
		this.idTextField = new TextField("输入ID", null, 3, TextField.NUMERIC);
		this.nameTextField = new TextField("输入名", null, 30, TextField.ANY);
		this.pathTextField = new TextField("输入路径", null, 15, TextField.ANY);
		this.append(idTextField);
		this.append(nameTextField);
		this.append(pathTextField);
	    this.modifyAlert.addCommand(confirmCommand);
		this.modifyAlert.addCommand(cancelCommand);
		this.modifyAlert.setCommandListener(this); 
		this.addCommand(backCommand);
		this.addCommand(okCommand);
		this.setCommandListener(this);
	}

	public void showForm(Display display, PhotoBookMenu photoBookMenu)	//用来显示界面
	{
		this.display = display;
	   	this.photoBookMenu = photoBookMenu;
		this.display.setCurrent(this);
	}

	public void commandAction(Command c,Displayable s)
	{
		if(c == backCommand)
		{
			this.display.setCurrent(photoBookMenu);
		}

		if( c == okCommand)
		{								
			this.pb = new PhotoBook();
			try
			{
				_id = Integer.parseInt(idTextField.getString());
			}
			catch(NumberFormatException e)
			{
				this.display.setCurrent(infoAlert);
				isAdd = false;
			}
			_name = nameTextField.getString();
			_path = pathTextField.getString();
			int recordID = pb.getRecordIDByID(_id);
			if (_name.compareTo("") == 0)
			{
				this.display.setCurrent(infoAlert);
				isAdd = false;
			}
			if (_path.compareTo("") == 0)
			{
				this.display.setCurrent(infoAlert);
				isAdd = false;
			}	    			
			if (isAdd == true)
			{
				//如果记录中没有对应的记录则增加一条
				if (recordID == -1)
				{
					pb.addPhoto (_id, _name, _path);//addAlert.setString("操作成功");				
					this.display.setCurrent(addAlert);
				}			
				//如果已存在一条对应的记录,则修改对应的记录
				else
				{
					this.display.setCurrent(modifyAlert);
				}
			}
			isAdd = true; //重新设置我真,保证下次运行正常
			pb.closeRS();
		}

		if (c == confirmCommand)
		{
			pb.modifyPhoto (_id, _name, _path);
			this.display.setCurrent(this);
		}
		
		if (c == cancelCommand)
		{
			this.display.setCurrent(this);
		}
		
	}  
}




⌨️ 快捷键说明

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