import java.awt.Color; import java.awt.*; import javax.swing.Timer; import java.awt.event.*; public class Dot { private int x, y, size ; private Color color; private Timer wait, duration; boolean visable; public Dot(int x, int y, int size, Color c, ActionListener app, int w, int dur) { this.x = x; this.y = y; this.size = size; color = c; visable = false; wait = new Timer(w, app); duration = new Timer(dur, app); color = c; //color = randomColor(); } public void start(){ wait.start(); } public Timer getWaitTimer(){ return wait; } public Timer getDurationTimer(){ return duration; } public boolean isVisable(){ return visable;} public void setVisable(boolean b){ visable = b;} public boolean contains (int a, int b) { if (!visable) return false; double r = .5 * size; double dx = (this.x + r) -a; double dy = (this.y + r) -b; //return (int)(Math.sqrt(dx*dx+dy*dy )); return (dx*dx + dy*dy <= r*r); } /** * randomInt * @param min * @param max * @return a random integer from min to max (inclusive) */ public int randomInt(int min, int max){ return min + (int)(Math.random()*(max-min+1)); } /** * randomColor * @return random Color */ public Color randomColor() { return new Color( randomInt(0,255), randomInt(0,255), randomInt(0,255)); } /** * draw * @param The graphics object to draw itself */ public void draw(Graphics g) { if (visable) { g.setColor(color); g.fillOval(x, y, size, size); } } }