Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Paint methode is running four times, I dont know why,

    My Paint method is running four times, I don't know why.........
    I am using JApplet and my paint method is running four time, from where paint method is call.........please help me, I want to run paint method at once at a time in applet.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Paint methode is running four times, I dont know why,

    Don't let it bother you. Did you expect that your Applet wouldn't be painted without an explicit repaint()?

    Redesign so that you don't have any calculations or business logic that depend on how many times a painting method executes (over which you have no control).

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: Paint methode is running four times, I dont know why,

    The following is the applet code that have paint method.......

    public void paint(Graphics g) {
    //System.out.println("paint");
    super.paintComponents(g); // Required
    g.drawImage(Casino_table_img, 20, 20, this);
    try
    {

    for(int j =0; j <10; j++)
    {
    System.out.println(j);
    System.out.println("ok");
    Random rgen = new Random();
    int randomPosition = rgen.nextInt(cards.length);
    ShowCard c = _deck[randomPosition];
    g.drawImage(c.image, x1[j],y1[j], this );

    g.drawImage(c.image,x2[j],y2[j], this);
    g.drawImage(img1,x2[j],y2[j], this);
    g.drawImage( c.img, x3[0],y3[0], this );

    }
    }
    catch (Exception e) {
    System.err.println("Caught IOException: " + e.getMessage());
    }

    }//end paintComponent


    my for loop is running 4 times , it means that my paint method is calling 4 times from other side I am not finding......

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Paint methode is running four times, I dont know why,

    Did you even read my response?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: Paint methode is running four times, I dont know why,

    yes,

    I have not used repaint() method anywhere in the program,
    I am using g.drawImage(image,int,int,this) , its run in only paint method so my loop and my logic will be work inside paint method....
    anything else you want........

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Paint methode is running four times, I dont know why,

    Quote Originally Posted by DarrylBurke View Post
    Redesign so that you don't have any calculations or business logic that depend on how many times a painting method executes (over which you have no control).
    Do I need to repeat the rest of it too?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: Paint methode is running four times, I dont know why,

    ok,
    now the 10-10 crds draw from the following code i loop
    g.drawImage(c.image,x2[j],y2[j], this);
    g.drawImage(img1,x2[j],y2[j], this);

    Here img1 is a image from img1 = getImage(getCodeBase(),"cards/b.gif");
    so above code is required for my paint method is running four time ........
    Please reply me if anything you want.........

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Paint methode is running four times, I dont know why,

    Since you have started a new thread for your related question, I'm closing this one.

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 7
    Last Post: 05-05-2011, 04:26 PM
  2. EOF methode
    By Dipke in forum New To Java
    Replies: 7
    Last Post: 10-02-2010, 03:50 PM
  3. Replies: 10
    Last Post: 09-17-2010, 04:04 AM
  4. using paint methode in another class
    By imorio in forum New To Java
    Replies: 8
    Last Post: 08-12-2010, 03:17 PM
  5. Why the paint() method is called two times ?
    By supremo in forum New To Java
    Replies: 4
    Last Post: 06-03-2010, 06:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •