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

📄 singerphoto.java

📁 手机在线系统 采用Java 中的J2ME, JSP 跟MySql 运行环境是:jsdk1.4以上
💻 JAVA
字号:
/**
 * @(#)SingerPhoto.java	1.11 01/08/23
 * Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
 * @version 	1.0, 10/05/2004
 * @author 	饶荣庆
 * @author 	余煜辉
 */
package com.j2me.recreation.singer;

import com.j2me.language.*;
import com.j2me.recreation.*;
import com.j2me.main.*;
import com.j2me.common.*;
import java.io.*;
import javax.microedition.lcdui.*;

/**
 *此类是浏览网络图片的类
 */
public class  SingerPhoto extends Form implements CommandListener
{

	private Display display;
	private RecreationMenu recreation;

	private Command backCommand = null;		
	private Command nextCommand = null;
	private Command upCommand = null;
	public ImageItem photo; //显示艺术家图片
	public StringItem download; //显示下载信息

	
	/*错误*/
	private Alert errorAlert = null;

	private Image image = null;
	private int i = 1; //第几个图片
	private int over;
	private String url;
	private String strURL = null;


	public SingerPhoto(Image image, String url)
	{
		super("");
		this.url = url;
		this.backCommand = new Command("返回", Command.BACK, 2);	
		this.nextCommand = new Command("下一张", Command.BACK, 2);	
		this.photo = new ImageItem("相片:", null, Item.LAYOUT_CENTER, "");
		this.upCommand = new Command("上一张", Command.BACK, 2);
		if (image != null)
		{
			this.photo.setImage(image);
		}
		this.download = new StringItem("下载:", "");
		this.append(download);
		this.append(photo);
		this.addCommand(backCommand);
		this.addCommand(nextCommand);
		this.setCommandListener(this);
	}

	/*显示菜单界面方法*/
	public void showForm(Display display, RecreationMenu recreation)	//用来显示界面
	{		
		this.display = display;
	   	this.recreation = recreation;
		this.display.setCurrent(this);
	} 

    /**
	 *下载网络图片的方法
	 */
	private void downloadImage(String uRL)
	{
		strURL = uRL;
		/*加快下载速度的线程*/
		Thread t = new Thread()
		{
			
			public void run() 
			{
				

				try
				{	
					download.setText("正在下载.....");
					//从网络上获取图象资源
			        image = ConnectHttp.getJspImage(strURL);  
					//"http://127.0.0.1:8080/jsp/recreation/image/twins.png");
					download.setText("下载完成");
					try
					{
						photo.setImage(image);
					}
					catch(IllegalArgumentException i)
					{
						System.out.println("fdsf" + i.getMessage());
					}
					addCommand(nextCommand);

		        }
		        catch(IOException e)
		        {
					errorAlert  = new Alert("ERROR", "对不起!连接错误", null, AlertType.ERROR);	
					errorAlert.setTimeout(2000);
					display.setCurrent(errorAlert);
					System.out.println(e);
			    }
				catch(NullPointerException e)
				{
					System.out.println(e);
				}
				catch(IllegalArgumentException e)
				{
					over = -1;
					errorAlert  = new Alert("ERROR", "对不起!下载图片时出错,可能是已经浏览完成,请重新浏览!", null, AlertType.ERROR);	
					errorAlert.setTimeout(2000);
					display.setCurrent(errorAlert);
					System.out.println(e);
					download.setText("连接错误");
					addCommand(nextCommand);
				}
			}
		};
		
		//启动线程
		t.start();
	}



	public void commandAction(Command c, Displayable s)
	{
		if (c == backCommand)
		{
			this.display.setCurrent(recreation);
		}
		else
		{
			download.setText("连接网络.....");

			/*说明已经浏览完成*/
			if (over == -1)
			{
				i = 1;
				over = 0;
				downloadImage(url + i + ".png");
				i++;
			}
			else
			{
				downloadImage(url + i + ".png");
				i++;
			}
			this.removeCommand(nextCommand);

		}
	}
}


⌨️ 快捷键说明

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