//Example08
import java.awt.*;
import java.awt.event.*;
public class Example08 extends Frame implements MouseListener{
Image[] img=new Image[32];
int x,y;
int cnt=0;
//Main
public static void main(String ar[]){
Frame f=new Example08();
f.setTitle("A lot of chicken(Please Click!)");
f.setSize(640,400);
f.setVisible(true);
}
//Frame
Example08(){
int i;
String imgname;
setLayout(new FlowLayout());
for(i=0;iថi++){
imgname="cut" + (int)(Math.random()*7) + ".gif";
img[i]=Toolkit.getDefaultToolkit().getImage(imgname);
}
addMouseListener(this);
addWindowListener(new WinAdapter());
}
//Close
class WinAdapter extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
//Paint
public void update(Graphics g){
g.drawImage(img[cnt],x-29,y-42,this);
}
//Mouse event
public void mouseClicked(MouseEvent me){
cnt=cnt+1;
if (cnt==32) cnt=0;
x=me.getX();
y=me.getY();
repaint();
}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mouseMoved(MouseEvent me){}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
}