The animated GIF for this assignment can be found in HTML One, assignment
13 (click on the "more examples" link).
|
Working With Animated GIFs:
To Take Keyboard Input Add to Init Method:
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e){
if(e.getKeyCode()==KeyEvent.VK_UP){
amt+=25;
if(amt>1000) amt=1000;
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN){
amt-=25;
if(amt<0) amt=0;
}
repaint();
}
});
Also Add These Methods To Normal Image Loading and Displaying Code:
public void addNotify() {
super.addNotify();
setBounds(10,10,60,60);
}
public boolean imageUpdate(Image image, int flags,
int x, int y, int w, int h) {
if((flags & FRAMEBITS) != 0) {
try{
Thread.currentThread().sleep(amt);
}
catch(Exception e) { }
repaint();
}
return true;
}
public void update(Graphics g){
g.fillRect(10,10,100,50);
paint(g);
}
}
|