if I set (e.g. g.setOval) by direct way I get one Oval on window but If I set Object with creating g.setOval inside I sometimes get more than one Oval on window (2,3 or 4), look on code.
-Why do this can explain me? -How I can create Graphics inside my Object and get one Oval after one call Object. (no 2,3 or 4)
public class Obj {
Random rand;
private int x, y;
public void paintc (Graphics g,int x, int y) {
g.fillOval(x,y,20,20);
System.out.println(x + " : " +y);
}
}
public class Main extends JPanel{
private Obj obj;
Random rand;
public Main () {
obj = new Obj();
}
public void paint(Graphics g) {
rand = new Random();
int x = rand.nextInt(300 - 20);
int y = rand.nextInt(200 - 20);
obj.paintc(g,x,y); //by this way I sometimes get more than one Oval why????
g.fillOval(x,y,20,20); //by this way I get one oval It is alright
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.add(new Main());
}
}