import java.awt.BorderLayout; import java.awt.Cursor; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; import javax.imageio.ImageIO; import javax.swing.JApplet; import javax.swing.JFrame; /** * @author DanO *This is designed to run as an applet or an application */ public class WebCamDisplay extends JApplet { ArrayList pictures = new ArrayList(); static int kWidth = 800; static int kHeight= 600; /** * Constructor * */ public WebCamDisplay() { //call up all the picture files local or from the web pictures = getPicturesInWebDirectory("http://itp.nyu.edu/~dbo3/VideoSensing/test/"); //pictures = getPicturesInFileDirectory("C:\\",false); repaint(); } /** * Lazy * */ public void put(String s){ System.out.println(s); } /** * This is like the main of applets, called automatically by the browser. If you are in an application * it gets called manually in the main method. * */ public void init() { setSize(kWidth,kHeight); } /** * This is a bit like the main of applets, called just after init automatically by the browser. If you are in an application * it gets called manually in the main method. * */ public void start() { repaint(); } /** * Main is ignored if this is running as an applet. If it runs as * an application we make a Frame that acts like the browser to give a home to the applet. * */ public static void main(String[] args) { WebCamDisplay myDisplayApplet = new WebCamDisplay(); JFrame frame = new JFrame(); frame.setVisible(true); frame.setSize(kWidth,kHeight); frame.getContentPane().add(myDisplayApplet, BorderLayout.CENTER); myDisplayApplet.init(); myDisplayApplet.start(); } /** * Paint the pictures on the screen. For home work you might * try to fit them into a grid or something fancier. * */ public void paint(Graphics g) { for (int i = 0; i < pictures.size(); i++){ BufferedImage bi = (BufferedImage) pictures.get(i); g.drawImage(bi, i*bi.getWidth(), 0, null); } } /** * Get a list of pictures from a web directory * */ public ArrayList getPicturesInWebDirectory(String _dir) { // for this to work you have to make you directory listing visible to // the web // by adding a file called ".htacces" with one line "DirectoryIndex // showit" in it. ArrayList pics = new ArrayList(); try { URL myURL = new URL(_dir); BufferedReader dis = new BufferedReader(new InputStreamReader(myURL.openStream())); // InputStreamReader isr = new InputStreamReader(myURL.openStream()) String line = dis.readLine(); while (line != null) { if (line.indexOf("img src=\"/icons/image2.gif") != -1) { String frontMark = "