All pastes #2051196 Raw Edit

Anonymous

public text v1 · immutable
#2051196 ·published 2011-04-27 13:41 UTC
rendered paste body
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;

public class Animacia extends JApplet {

    int n = 0;
    int b = 255;
    int width, height;
    Image buffer;
    Graphics bg;
    
    Timer t = new Timer(20, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            repaint();
            n++;
            if (n>=20) n = 0;
            bg.clearRect(0, 0, width, height);
            for (int i=100;i>0;i--) {
                if (i%2==0) b = 255; else b = 0;
                bg.setColor(new Color(b, b, b));
                bg.fillOval(width/2+n-i*10, height/2+n-i*10, i*20-n*2, i*20-n*2);
            }
        }
    });
    
    public void init() {
        width = getSize().width;
        height = getSize().height;
        buffer = createImage(width, height);
        bg = buffer.getGraphics();
        t.start();
    }
    
    public void update(Graphics g) {
       g.drawImage(buffer, 0, 0, this);
    }

    public void paint(Graphics g) {
       update(g);
    }
}