
-----------------------------------
xHoly-Divinity
Tue Jan 17, 2006 5:06 pm

Java - Flickering (fast help needed)
-----------------------------------

import java.applet.*;
import java.awt.*;

public class BouncePicApplet extends Applet implements Runnable
{

    int x, y;
    int dx, dy;
    int appletWidth, appletHeight;

    public void run ()
    {
        while (true)
        {
            try
            {
                Thread.sleep (50);
            }
            catch (InterruptedException e)
            {
            }
            if ((x + dx < 0) || (x + 100 > appletWidth))
            {
                dx = -dx;
            }
            if ((y + dy < 0) || (y + 100 > appletHeight))
            {
                dy = -dy;
            }
            x += dx;
            y += dy;
            repaint ();
        }
    }


    public void init ()
    {
        x = 0;
        y = 0;
        dx = 3;
        dy = 3;

        appletWidth = getSize ().width;
        appletHeight = getSize ().height;

        Thread t = new Thread (this);
        t.start ();
    }


    public void paint (Graphics g)
    {
        g.fillOval (x, y, 100, 100);
    }
}


I know that the circle does not appear to flicker, however, if u have a full screen applet with lots of large picture it flickers like crazy, it also depends on the computer. How to fix this problem, if anyone could fill in the code... that would be much appreciated :)

-----------------------------------
rizzix
Wed Jan 18, 2006 1:11 am


-----------------------------------
double buffering helps.. seach this forum.. you'll find your solution

-----------------------------------
xHoly-Divinity
Wed Jan 18, 2006 4:49 pm


-----------------------------------
Couldn't find it.... can u just start me off....

-----------------------------------
wtd
Wed Jan 18, 2006 4:54 pm


-----------------------------------
Google for "double buffering" and restrict your search to java.sun.com.

Learning how to search effectively is more important than the answer in this case.

-----------------------------------
xHoly-Divinity
Wed Jan 18, 2006 5:23 pm


-----------------------------------
http://java.sun.com/developer/J2METechTips/2001/tt0725.html

That's the site i managed to find.... didn't help much though :S

-----------------------------------
wtd
Wed Jan 18, 2006 5:34 pm


-----------------------------------
Because that's for use with cellphones and PDAs.

-----------------------------------
xHoly-Divinity
Wed Jan 18, 2006 5:44 pm


-----------------------------------
Common dude.... can u just help me out

-----------------------------------
wtd
Wed Jan 18, 2006 5:59 pm


-----------------------------------
We are helping you.

What we will not do is simply hand you the answer on a silver platter.
