photolist.java
来自「手机在线系统 采用Java 中的J2ME, JSP 跟MySql 运行环」· Java 代码 · 共 115 行
JAVA
115 行
/**
* @(#)PhotoList.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 com.j2me.language.*;
import java.util.*;
import javax.microedition.lcdui.*;
/**
*此类的功能是用指定的方式排序用户。并把用户输出的列表上
*/
public class PhotoList extends List implements CommandListener
{
private Display display = null;
private PhotoBookMenu photoBookMenu = null;
private DetailInfoForm detailInfoForm = null;
public Command infoCommand = null;
public Command backCommand = null;
private String aString;
private PhotoBook pb = null;
private Vector vectorPhotos = null;
private Enumeration enumerationVector;
private Photo photo;
private int sortBy; //指定排序方式获得对象
public PhotoList(String s, int _sortBy)
{
super(s, Choice.IMPLICIT);
this.sortBy = _sortBy; //以指定方式来列表。0为相片名,1为id
this.infoCommand = new Command("详细信息", Command.OK, 2);
this.backCommand = new Command("返回", Command.BACK, 2);
this.addCommand(backCommand);
this.addCommand(infoCommand);
this.setCommandListener(this);
}
public void showForm(Display display, PhotoBookMenu photoBookMenu) //用来显示界面
{
this.initList();
this.display = display;
this.photoBookMenu = photoBookMenu;
this.display.setCurrent(this);
}
public void initList()
{
this.pb = new PhotoBook();
this.vectorPhotos = pb.getAllPhotos (sortBy); //根据指定的排序方式,获得Friend对象
if (vectorPhotos.isEmpty())
{
this.removeCommand(infoCommand);
}
else
{
this.addCommand(infoCommand);
}
this.enumerationVector = vectorPhotos.elements();
this.pb.closeRS();
while (enumerationVector.hasMoreElements()) //把存储的对象一个个读出来并显示在列表上
{
photo = (Photo)enumerationVector.nextElement();
if (photo.getID()<10)
{
this.append("00" + photo.getID() + " | " + photo.getName() + " | " + "/myphoto/" + photo.getPath() + ".png", null);
}
else if (photo.getID()<100)
{
this.append("0" + photo.getID() + " | " + photo.getName() + " | " + "/myphoto/" + photo.getPath() + ".png", null);
}
else
{
this.append(photo.getID() + " | " + photo.getName() + " | " + "/myphoto/" + photo.getPath() + ".png", null);
}
}
}
public void commandAction(Command c,Displayable s)
{
if(c == backCommand)
{
this.display.setCurrent(photoBookMenu);
}
if (c == infoCommand)
{
if (Language.isEnglish == true) //修改语言为英文
{
this.detailInfoForm = new DetailInfoForm("Detail Info");
this.detailInfoForm.idItem.setLabel("ID:");
this.detailInfoForm.nameItem.setLabel("Name:");
this.detailInfoForm.pathItem.setLabel("Path:");
this.detailInfoForm.showForm(display, this, photoBookMenu, null, this.getString(this.getSelectedIndex()));
}
else
{
this.detailInfoForm = new DetailInfoForm("详细信息");
this.detailInfoForm.idItem.setLabel("ID:");
this.detailInfoForm.nameItem.setLabel("图片名:");
this.detailInfoForm.pathItem.setLabel("路径:");
this.detailInfoForm.showForm(display, this, photoBookMenu, null, this.getString(this.getSelectedIndex()));
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?