Threadanimator;DimensionoffDimension;ImageoffImage;GraphicsoffGraphics;Imageframes[];/** *inicializa parametros a serem usados na thread */publicvoidinit(){appletResize(1024,768);Stringstr=getParameter("fps");intfps=(str!=null)?Integer.parseInt(str):10;delay=(fps>0)?(1000/fps):100;// delay no fps operador ternárioToolkitt=Toolkit.getDefaultToolkit();frames=newImage[33];//lembrar de colocar o array com o tamanho dos arquivosfor(inti=1;i<33;i++){frames[i-1]=t.getImage("c:/teste"+(i+1)+".gif");}}/** * Metodo chamado qnd a applet se torna visivel * Cria a thread e começa */publicvoidstart(){animator=newThread(this);animator.start();}/** * metodos chamados na thread qnd ela começa * Faz a animação" */publicvoidrun(){// Remember the starting timelongtm=System.currentTimeMillis();while(Thread.currentThread()==animator){// Display the next frame of animation.repaint();// Delay depending on how far we are behind.try{tm+=delay;Thread.sleep(Math.max(0,tm-System.currentTimeMillis()));}catch(InterruptedExceptione){break;}// Advance the frameframe++;}}/** * This method is called when the applet is no longer * visible. Set the animator variable to null so that the * thread will exit before displaying the next frame. */publicvoidstop(){animator=null;offImage=null;offGraphics=null;}/** * Update a frame of animation. */publicvoidupdate(Graphicsg){Dimensiond=size();// Create the offscreen graphics contextif((offGraphics==null)||(d.width!=offDimension.width)||(d.height!=offDimension.height)){offDimension=d;offImage=createImage(d.width,d.height);offGraphics=offImage.getGraphics();}// Erase the previous imageoffGraphics.setColor(getBackground());offGraphics.fillRect(0,0,d.width,d.height);offGraphics.setColor(Color.black);// Paint the frame into the imagepaintFrame(offGraphics);// Paint the image onto the screeng.drawImage(offImage,0,0,null);}/** * Paint the previous frame (if any). */publicvoidpaint(Graphicsg){update(g);}/** * Paint a frame of animation. */publicvoidpaintFrame(Graphicsg){g.drawImage(frames[frame%10],0,0,null);//mudar aki tamanho da imagem impressa}publicvoidappletResize(intwidth,intheight){// TODO Auto-generated method stub}
Assim vc corre o risco do pessoal nem ler seu codigo inteiro
Falow
T+
silva.fernandes
Cara… posta os código dentro da Tag Code …
Fica melhor para visualizarmos. …
Assim
Tá vendo como o resultado é bem melhor !!!
Assim vc corre o risco do pessoal nem ler seu codigo inteiro
Falow
T+
F
fabioSCSnoobie
Como faço para que as imagens que este programa gera sejam impressas em uma window? eu tentei fazer criando um novo objeto window mas deu errado.
importjava.applet.AppletStub;importjava.awt.*;publicclassScreenShowextendsjava.applet.AppletimplementsRunnable,AppletStub{intframe;intdelay;Windowjanela;Threadanimator;DimensionoffDimension;ImageoffImage;GraphicsoffGraphics;Imageframes[];/***inicializa parametros a serem usados na thread*/publicvoidinit(){appletResize(1024,76;Stringstr=getParameter("fps");intfps=(str!=null)?Integer.parseInt(str):10;delay=(fps>0)?(1000/fps):100;// delay no fps operador ternárioToolkitt=Toolkit.getDefaultToolkit();frames=newImage[33];//lembrar de colocar o array com o tamanho dos arquivosfor(inti=1;i<33;i++){frames[i-1]=t.getImage("c:/teste"+(i+1)+".gif");}}/*** Metodo chamado qnd a applet se torna visivel* Cria a thread e começa*/publicvoidstart(){animator=newThread(this);animator.start();}/*** metodos chamados na thread qnd ela começa* Faz a animação"*/publicvoidrun(){// Remember the starting timelongtm=System.currentTimeMillis();while(Thread.currentThread()==animator){// Display the next frame of animation.repaint();// Delay depending on how far we are behind.try{tm+=delay;Thread.sleep(Math.max(0,tm-System.currentTimeMillis()));}catch(InterruptedExceptione){break;}// Advance the frameframe++;}}/*** This method is called when the applet is no longer* visible. Set the animator variable to null so that the* thread will exit before displaying the next frame.*/publicvoidstop(){animator=null;offImage=null;offGraphics=null;}/*** Update a frame of animation.*/publicvoidupdate(Graphicsg){Dimensiond=size();// Create the offscreen graphics contextif((offGraphics==null)||(d.width!=offDimension.width)||(d.height!=offDimension.height)){offDimension=d;offImage=createImage(d.width,d.height);offGraphics=offImage.getGraphics();}// Erase the previous imageoffGraphics.setColor(getBackground());offGraphics.fillRect(0,0,d.width,d.height);offGraphics.setColor(Color.black);// Paint the frame into the imagepaintFrame(offGraphics);// Paint the image onto the screeng.drawImage(offImage,0,0,null);}/*** Paint the previous frame (if any).*/publicvoidpaint(Graphicsg){update(g);}/*** Paint a frame of animation.*/publicvoidpaintFrame(Graphicsg){g.drawImage(frames[frame%10],0,0,null);//mudar aki tamanho da imagem impressa}publicvoidappletResize(intwidth,intheight){// TODO Auto-generated method stub}}
silva.fernandes
public void init() {
appletResize(1024,76;
Falta fechar um parenteses …
T+
rodrigo1
bom ... fiz algumas modificações ... vê se é o que vc tava querendo ...
importjava.awt.*;importjavax.swing.JFrame;publicclassScreenShowextendsJFrameimplementsRunnable{intframe;intdelay;Threadanimator;DimensionoffDimension;ImageoffImage;GraphicsoffGraphics;Imageframes[];/** * inicializa parametros a serem usados na thread */publicScreenShow(Stringstr){setSize(300,300);intfps=(str!=null)?Integer.parseInt(str):10;delay=(fps>0)?(1000/fps):100;// delay no fps operador// ternárioToolkitt=Toolkit.getDefaultToolkit();frames=newImage[33];// lembrar de colocar o array com o tamanho dos// arquivosfor(inti=1;i<33;i++){frames[i-1]=t.getImage("c:/teste"+(i+1)+".gif");}}/** * Metodo chamado qnd a applet se torna visivel Cria a thread e começa */publicvoidstart(){animator=newThread(this);animator.start();}/** * metodos chamados na thread qnd ela começa Faz a animação" */publicvoidrun(){// Remember the starting timelongtm=System.currentTimeMillis();while(Thread.currentThread()==animator){// Display the next frame of animation.repaint();// Delay depending on how far we are behind.try{tm+=delay;Thread.sleep(Math.max(0,tm-System.currentTimeMillis()));}catch(InterruptedExceptione){break;}// Advance the frameframe++;}}/** * This method is called when the applet is no longer visible. Set the * animator variable to null so that the thread will exit before displaying * the next frame. */publicvoidstop(){animator=null;offImage=null;offGraphics=null;}/** * Update a frame of animation. */publicvoidupdate(Graphicsg){Dimensiond=size();// Create the offscreen graphics contextif((offGraphics==null)||(d.width!=offDimension.width)||(d.height!=offDimension.height)){offDimension=d;offImage=createImage(d.width,d.height);offGraphics=offImage.getGraphics();}// Erase the previous imageoffGraphics.setColor(getBackground());offGraphics.fillRect(0,0,d.width,d.height);offGraphics.setColor(Color.black);// Paint the frame into the imagepaintFrame(offGraphics);// Paint the image onto the screeng.drawImage(offImage,100,100,null);}/** * Paint the previous frame (if any). */publicvoidpaint(Graphicsg){update(g);}/** * Paint a frame of animation. */publicvoidpaintFrame(Graphicsg){g.drawImage(frames[frame%10],0,0,null);// mudar aki tamanho da// imagem impressa}}
flw...
F
fabioSCSnoobie
Nossa kra eu nao vi direito ainda, mas testei agora e ta pegando, e tah ate mais rapido do q antes, BRIGADAO kra vlw msm!!!
bem o lado da janela ta funcionando, agora qnd mudo para algo superior a 10 da um
Exception in thread “Image Fetcher 0” java.lang.OutOfMemoryError: Java heap space
axo q tow com algum vazamento d memoria ow seila, vow da uma estudada nisso, d qlqr forma esse lance da janela me ajudo mto kra