veryfree | ca c le refresh d'un image a partir d'une cam:
Code :
- import java.awt.*;
- import java.applet.*;
- public class HobCam extends Applet implements Runnable{
- Image myPic;
- Thread spinThread;
- boolean animateFlag = true;
- public void init(){
- myPic = getImage(getCodeBase(),getParameter("image" ));
- }
- public void start(){
- spinThread = new Thread(this,"Image Thread" );
- spinThread.start();
- }
- public void stop(){
- animateFlag = false;
- }
- public void run(){
- if(((Thread.currentThread()).getName()).equals("Image Thread" )){
- while(animateFlag){
- myPic.flush();
- myPic = getImage(getCodeBase(),getParameter("image" ));
- repaint();
- try{Thread.sleep(1000);}
- catch(InterruptedException e){}
- }
- }
- }
- public void paint (Graphics g){
- if (myPic != null){
- g.drawImage(myPic,0,0,this);
- }
- }
- public void update(Graphics g){
- paint(g);
- }
- }
|
|