I wrote a code about circle starts to grow followed by finner circles, with each new one disappearing earlier while growing but in my code it is only growing how can I disappear the early one??
I didnt put the main method only classes
import java.util.ArrayList;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DotsPanel extends JPanel
{
private final int MAX_WIDTH = 300;
private final int RING_WIDTH = 10;
int x = 300, y = 300, diameter=0;
Color clr;
int f;
public ArrayList<Circle> pointList,pointList1;
public DotsPanel(Color c,int a)
{
pointList = new ArrayList<Circle>();
setBackground (Color.white);
setPreferredSize (new Dimension(300, 200));
PaintAction action = new PaintAction();
Timer timer = new Timer(a, action);
timer.start();
}
private class PaintAction implements ActionListener {
public void actionPerformed(ActionEvent evt) {
repaint(); // Call the repaint() method in the panel class.
}
}
public void paintComponent (Graphics page)
{
super.paintComponent(page);
Circle c=new Circle(diameter,x,y,clr);
pointList.add(c);
diameter += (2 * RING_WIDTH);
x -= RING_WIDTH;
y -= RING_WIDTH;
for (Circle a : pointList) {
a.draw(page);
}
}
}
import java.awt.*;
//Circle
class Circle {
//=========================================================== fields
int _x; // x coord of bounding rect upper left corner.
int _y; // y coord of bounding rect upper left corner.
int _diameter; // Height and width of bounding rectangle.
Color _color;
//====================================================== constructor
Circle( int diameter,int x, int y,Color color) {
_x = x;
_y = y;
_diameter = diameter;
_color=color;
}
//============================================================= draw
void draw(Graphics g) {
g.setColor(_color);
g.drawOval(_x, _y, _diameter, _diameter);
}
}