基于DM642的JPEG图象编解码的网络传输程序

源代码在线查看: easycam.java

软件大小: 402 K
上传用户: eeworm
关键词: JPEG 642 DM 图象
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.awt.*;
				import java.applet.*;
				import java.net.*;
				
				public class easyCam extends Applet {
				  private Image  myImage = null;
				
				  private int startIndex = 1;
				  private int endIndex = 9;
				  private int currentIndex;
				
				  private int sleepTime = 500;
				
				  private String fileBase;
				  private String fileExtension;
				
				  private Thread timerThread;
				  private volatile boolean noStopRequested;
				  private MediaTracker tracker;
				
				
				  public void init() {
				    tracker = new MediaTracker(this);
					String strStartIndex = getParameter("STARTINDEX");
					String strEndIndex   = getParameter("ENDINDEX");
				    String strSleepTime  = getParameter("MSDELAY");
				    fileBase             = getParameter("FILEBASE");
					fileExtension        = getParameter("FILEEXT");
				
				    if (strStartIndex != null)
					    startIndex = Integer.parseInt(strStartIndex);
				    if (strEndIndex != null)
					    endIndex = Integer.parseInt(strEndIndex);
				    if (strSleepTime != null)
					    sleepTime = Integer.parseInt(strSleepTime);
				
				    startThread();
				  }
				
				  private void startThread() {
				    noStopRequested = true;
				
				    Runnable r = new Runnable() {
				      public void run() {
				        runWork();
				      }
				    };
				
				    timerThread = new Thread(r, "Timer");
				    timerThread.start();
				  }
				
				  private void stopThread() {
				    noStopRequested = false;
				    timerThread.interrupt();
				  }
				
				  private void runWork() {
				    currentIndex = startIndex;
				    boolean imageload = false;
				
				    try {
				      while ( noStopRequested ) {
				        currentIndex = currentIndex + 1;
				        if( currentIndex > endIndex )
				          currentIndex = startIndex;
				
				        if( imageload == true ) {
					      tracker.removeImage(myImage);
				          myImage.flush();
				          myImage = null;
					    }
				        myImage = getImage(getDocumentBase(), fileBase + Integer.toString(currentIndex) + fileExtension);
					    tracker.addImage(myImage, 0);
						tracker.waitForAll();
					    imageload = true;
				
				        repaint();
				
				        Thread.sleep( sleepTime );
				      }
				    } catch ( InterruptedException x ) {
				      Thread.currentThread().interrupt();
				    }
				  }
				
				  public void paint(Graphics g) {
				    update(g);
				  }
				
				  public void update(Graphics g) {
					if( myImage != null ) {
					  g.drawImage(myImage, 0, 0, this);
				    }
				  }
				
				  public void destroy() {
				    stopThread();
				
				    myImage.flush();
				    myImage = null;
				  }
				}
							

相关资源