/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
flimmer under animation på trods af double~
Fra : Soren Christensen


Dato : 07-12-01 02:38

Hej jeg håber i bærer over med det engelske - jeg postede spørgsmålet i en
anden newsgroup.



My problem is screen flickering during execution of an applet.
The applet shows a ball bouncing against defined borders.
I run the position updating and doublebuffered painting in a seperate
thread.
From this thread, i call repaint().
Now i don't see why it should flicker when all the drawing is done before i
call repaint. All it has to do is to draw the doublebuffered image on
screen.

Here's the implemented methods from Runnable:

public void start()
{
mythread = new Thread(this,"mintraad");
mythread.start();
}

public void run()
{
Thread cThread = Thread.currentThread();
while (cThread == mythread)
{

for (int i = 0 ; i>-1 ; i++)
{
myball.moveit(); //updates position of ball
sG.drawImage(bground,0,0,this); // draws clean background

sG.fillOval(myball.x-ballradius,myball.y-ballradius,2*ballradius,2*ballradiu
s); //draws the ball on top of it
repaint();
delay(20);
}
}


Here's my paint method:


public void paint(Graphics g)
{
g.drawImage(s,0,0,this);
}




And the delay method:

public void delay(int millis)
{
try {Thread.sleep(millis);}
catch (Exception ign) {}
}



Hope it is not too confusing, i suppose most beginners have been through
this so maybe you've had the same problem.
Any help will be very appreciated!!
Soren






 
 
Martin Mouritzen (07-12-2001)
Kommentar
Fra : Martin Mouritzen


Dato : 07-12-01 02:41

After I finished the 3 Pan Galactic Gargle Blasters, "Soren
Christensen" <schr@mail1.stofanet.dk> just offered me, he muttered
some weird stuff, and I had to correct this gibberish:

>From this thread, i call repaint().

Prøv at lav (overskriv) følgende metode:

public void update(Graphics g) {
paint(g);
}
--
Martin Mouritzen.
The truth is out there! Does anyone know the URL?

Søg
Reklame
Statistik
Spørgsmål : 177501
Tips : 31968
Nyheder : 719565
Indlæg : 6408526
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste