Hello, this is related to the last thread I posted, but it is also different. I found something about ImageObserver with a google search and can't find much on it, I tried doing what the site on google did, but it didn't work with the simple test I wrote.
here's the test:
import java.awt.* ;
import java.awt.event.* ;
import java.awt.geom.* ;
import javax.swing.* ;
import javax.swing.event.* ;
import java.awt.image.* ;
import java.io.* ;
import javax.imageio.* ;
public class GifTest extends JFrame {
public GifTest ( ) {
setSize ( 400 , 400 ) ;
this.add(new GifTest2());
this.setBackground ( new Color ( 0 , 0 , 0 ) ) ;
this.setVisible ( true ) ;
repaint ( ) ;
}
public static void main ( String [ ] args ) {
new GifTest ( ) ;
}
}
import java.awt.* ;
import java.awt.event.* ;
import java.awt.geom.* ;
import javax.swing.* ;
import javax.swing.event.* ;
import java.awt.image.* ;
import java.io.* ;
import javax.imageio.* ;
import java.util.* ;
/**
* Write a description of class GifTest2 here.
* @author (your name)
* @version (a version number or a date)
*/
public class GifTest2 extends JComponent implements MouseListener, ImageObserver {
Image img = null ;
ArrayList < Integer > xs = new ArrayList < Integer > ( ) ;
ArrayList < Integer > ys = new ArrayList < Integer > ( ) ;
int cx;
int cy;
public void mouseClicked ( MouseEvent e ) {
xs.add(e.getX());
ys.add(e.getY());
cx=e.getX();
cy=e.getY();
repaint();
}
public void mousePressed ( MouseEvent e ) {}
public void mouseReleased ( MouseEvent e ) {}
public void mouseExited ( MouseEvent e ) {}
public void mouseEntered ( MouseEvent e ) {}
/**make a new GifTest*/
public GifTest2 ( ) {
addMouseListener(this);
try {
img = ImageIO.read ( new File ( "gifTest2.gif" ) ) ;
} catch ( IOException ioe ) {
System.out.println ( ioe ) ;
}
xs.clear();
ys.clear();
setBackground ( new Color ( 0 , 0 , 0 ) ) ;
repaint ( ) ;
}
public void paint ( Graphics g ) {
g.setColor ( new Color ( 0 , 0 , 0 ) ) ;
g.fillRect ( 0 , 0 , getWidth ( ) , getHeight ( ) ) ;
for ( int i =0;i<xs.size();i++ ) {
g.drawImage ( img , xs.get(i) , ys.get(i) , this ) ;
}
}
public boolean imageUpdated(Image img, int infoflags, int x, int y, int w, int h){
repaint();
return true;
}
}
why doesn't this work to animate the GIF, what am I misunderstanding?