import java.util.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.imageio.*;
import java.lang.Math;
import java.io.*;
public class VGKernel extends JPanel
{
public Rectangle screen, bounds;
public JFrame frame;
public VGTimerTask vgTask;
public RedBloodCell[] redCellArray = new RedBloodCell[10];
public Random RG = new Random();
public VGKernel()
{
super();
screen = new Rectangle(0, 0, 800, 600);
bounds = new Rectangle(0, 0, 800, 600);
for(int i = 0; i < redCellArray.length; i++)
{
redCellArray[i] = new RedBloodCell(RG.nextInt(bounds.width+1),RG.nextInt(bounds.height+1),(RG.nextInt(5)+4),bounds.width,bounds.height);
}
frame = new JFrame("VGKernel");
vgTask = new VGTimerTask();
}
class VGTimerTask extends TimerTask
{
public void run()
{
for(int j = 0; j < redCellArray.length; j++)
{
redCellArray[j].move();
}
frame.repaint();
}
}
public void paintComponent(Graphics g)
{
bounds = g.getClipBounds();
g.clearRect(screen.x, screen.y, screen.width, screen.height);
for(int k = 0; k < redCellArray.length; k++)
{
g.drawImage(redCellArray[k].img, redCellArray[k].x, redCellArray[k].y, this);
}
}
public static void main(String arg[])
{
java.util.Timer vgTimer = new java.util.Timer();
VGKernel panel = new VGKernel();
panel.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.frame.setSize(panel.screen.width, panel.screen.height);
panel.frame.setContentPane(panel);
panel.frame.setVisible(true);
vgTimer.schedule(panel.vgTask, 0, 20);
}
}