@Override public void run() /* take a picture every DELAY ms */ { camera = new VLCCapture(); // update panel and window sizes to fit video's frame size Dimension frameSize = camera.getFrameSize(); if (frameSize != null) { setMinimumSize(frameSize); setPreferredSize(frameSize); // top.pack(); // resize and center JFrame // top.setLocationRelativeTo(null); } long duration; BufferedImage im = null; isRunning = true; while (isRunning) { long startTime = System.currentTimeMillis(); im = camera.getImage(); // take a snap duration = System.currentTimeMillis() - startTime; if (im == null) System.out.println("Problem loading image " + (imageCount + 1)); else { image = im; // only update image if im contains something saveSnap(image, SAVE_FNM); imageCount++; totalTime += duration; repaint(); } if (duration < DELAY) { try { Thread.sleep(DELAY - duration); // wait until DELAY time has passed } catch (Exception ex) { } } } // save last image camera.close(); // close down the camera }
public void closeDown() /* Terminate run() and wait for the camera to be closed. This stops the application from exiting until everything has finished. */ { isRunning = false; while (!camera.isClosed()) { try { Thread.sleep(DELAY); } catch (Exception ex) { } } } // end of closeDown()