furutani 28 de nov. de 2009
deyvison 28 de nov. de 2009
ja indentifiquei o problema , acho q tinha haver com o diretorio (“images/” ). modifiquei os parametros q estavam dentro do for e deu certo,
so substitui o :
for ( int count = 0 ; count < images . length ; ++ count )
images [ count ] = new ImageIcon ( getClass (). getResource ( “ images / ” +
IMAGE_NAME + count + “ . gif ” ));
por:
for ( int count = 0 ; count < images . length ; count ++ )
images [ count ] = new ImageIcon ( getClass (). getResource ((
IMAGE_NAME + count + “ . gif ” )));
e funciou.
neeryck 28 de nov. de 2009
Vc colocou elas em um Array… por acaso o nome “animação” remete a várias fotos sendo mostradas rapidamente dando a ilusão de uma animação???
Como agregou esse trecho do código ao programa pra dar esse efeito de “animação”, mostra pra gente ae!
[]'s
deyvison 29 de nov. de 2009
aqui ta o codigo completo :
import java.awt. < em > ;
import javax.swing. </ em > ;
import java.awt.event. < em > ;
// import javax.swing. </ em > ;
public class animacao extends JPanel implements ActionListener{
protected String IMAGE_NAME = "image" ;
protected ImageIcon images [] ;
protected int TOTAL_IMAGES = 10 , currentImage = 0 , ANIMACAO_DELAY = 600 // tempo entre
// as imagens
, width , height ;
protected Timer animacaoTimer ;
public animacao ()
{
initializeanimacao ();
}
protected void initializeanimacao ()
{
images = new ImageIcon [ TOTAL_IMAGES ] ;
for ( int count = 0 ; count < images . length ; count ++ )
images [ count ] = new ImageIcon ( getClass (). getResource ((
IMAGE_NAME + count+ “.gif”))); //vai carregar as imagens (ex:“image1.gif”)
width = images [ 0 ] . getIconWidth ();
height = images [ 0 ] . getIconHeight ();
}
public void paintComponent ( Graphics g )
{
super . paintComponent ( g );
images [ currentImage ] . paintIcon ( this , g , 0 , 0 );
currentImage = ( currentImage + 1 ) % TOTAL_IMAGES ;
}
public void actionPerformed ( ActionEvent actionEvent )
{
repaint ();
}
public void startAnimacao ()
{
if ( animacaoTimer == null )
{
currentImage = 0 ;
animacaoTimer = new Timer ( ANIMACAO_DELAY , this );
animacaoTimer . start ();
}
else
if ( ! animacaoTimer . isRunning ())
animacaoTimer . restart ();
}
public void stopAnimacao ()
{
animacaoTimer . stop ();
}
public Dimension getMinimumSize ()
{
return getPreferredSize ();
}
public Dimension getPreferredSize ()
{
return new Dimension ( width , height );
}
public static void main ( String args [] )
{
animacao animacao1 = new animacao ();
JFrame window = new JFrame ( "Testando animacao" );
Container container = window . getContentPane ();
container . add ( animacao1 );
window . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );
window . pack ();
Insets insets = window . getInsets ();
window . setSize ( animacao1 . getPreferredSize (). width + insets . left + insets . right , animacao1 . getPreferredSize (). height + insets . top + insets . bottom );
window . setVisible ( true );
animacao1 . startAnimacao ();
}
}
davidbuzatto 29 de nov. de 2009
Deyvison,
Use a tag code para organizar seus fontes.