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

📄 camera.java

📁 Java source code IP Camera project for studying. Java源代碼的IP攝像頭項目的研究。
💻 JAVA
字号:
package sept.model;import java.io.File;import java.util.ArrayList;import java.awt.*;/** * Class Camera *  * Camera is a container class that stores photos taken by an IP Camera  * * @author Goran Mateski * @since v1.0 */public class Camera {	private ArrayList<Photo> photos;	private String name;      /* name of camera */	private String location; /* Directory of Camera */	private File   folder;	  /* Pointer to directory */	private String []fileNames; /* an array of filenames for the photos */		/**	 * Constructor	 * 	 * Builds a camera Object	 * @throws Exception 	 */	public Camera (String cameraName, String location) throws Exception{		this.name = cameraName;		this.photos = new ArrayList<Photo>();				/* File pointer points to the directory */		folder = new File(location);				/* if directory doesn't exist throw an exception. */		if(folder == null){			throw new Exception("Directory does not exist");		}				/* Put the names of files from the folder into an array of strings */		fileNames = folder.list();				updateImages();	}					/**	 * Method UpdateImageList	 * Retrieves a list of filenames from a directory.	 * 	 * @return Returns true if the files have changed since last access. Returns	 * false if the files have not changed.	 */	protected boolean updateImageList(){		//TODO: Fix this method it is buggy.		//File update = new File(location);		//String newFileNames[] = update.list();		//boolean changes = false;				/* if the number of files in a directory has not changed		 * check that the filenames have changed. *//*		if(newFileNames.length == fileNames.length){			for(int i = 0; i < newFileNames.length; i++){				if(!fileNames[i].equals(newFileNames[i]) ){					changes = true;				}			}		}		else {			changes = true;		}		*/				/* overwrite old list of filenames with new one */		//fileNames = newFileNames;				/* if any changes have occured, download the images again */		//if(changes)			//updateImages();			    updateImages();		//return changes;		return true;	}				/**	 * Method updateImages()	 * 	 * Downloads the images from a folder. Should only be used when updateImageList()	 * returns true.	 * 	 * I hope the computers at RMIT have plenty of RAM :S	 */	private void updateImages(){		Image image = null;		Photo p = null;				for(int i = 0; i < this.fileNames.length; i++){						try {				image = Toolkit.getDefaultToolkit().getImage(fileNames[i]);				p = new Photo(fileNames[i], image);				photos.add(p);			}			catch (Exception e){				e.printStackTrace();			}		}	}		/**	 * Method getName	 * @return Returns the name of the Camera	 */	public String getName(){		return name;	}					/**	 * Method getPhotos	 * 	 * Accessor method that retrieves all the photos taken by a camera.	 * @return Returns an ArrayList of Photo objects. (See Photo.java).	 */	protected ArrayList<Photo> getPhotos(){		return photos;	}				/**	 * Method getLocation	 * @return Returns the directory of the Camera.	 */	protected String getLocation(){		return location;	}}

⌨️ 快捷键说明

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