I've been searching through answers and all and I couldn't find a solution for my problem. I wish I can delete the previous circle (created on mouse click) when I create a new one ?
Thank you so much in advance. :)
package javaapplication1;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;
public class CercuriRandom extends Applet implements MouseListener{
int x,y,z,r,v,a;
Thread t;
Color culoare;
Random rand;
@Override
public void init(){
t=new Thread();
rand= new Random();
culoare=new Color(r, v, a);
addMouseListener(this);
}
@Override
public void update(Graphics g){
g.setColor(culoare);
g.fillRoundRect(x, y, z, z, z, z);
try {
Thread.sleep(25);
} catch (InterruptedException e) { }
//repaint();
}
@Override
public void mouseClicked(MouseEvent me) {
if (me.getButton()==MouseEvent.BUTTON1) {
r=rand.nextInt(256);
v=rand.nextInt(256);
a=rand.nextInt(256);
culoare=new Color(r,v,a);
x=rand.nextInt(getWidth());
y=rand.nextInt(getWidth());
z=rand.nextInt(100);
repaint();
}
}
@Override
public void mousePressed(MouseEvent me) {
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseEntered(MouseEvent me) {
}
@Override
public void mouseExited(MouseEvent me) {
}
}
I'll leave here the code needed for creating the circles. I've been searching through answers and all and I couldn't find a solution for my problem. I wish I can delete the previous circle (created on mouse click) when I create a new one ?
Thank you so much in advance. :)