Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2004, 10:53 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default flickering ducks!

Hi, im new to java......trying to learn!!

ive been given an assignment which involves creating a java game so i decided to go for the classic duck shoot game.

Ive created the background lake and the little ducks that swim accross the lake.

my problem is the little ducks flicker as they travel accross the page

ill post my code below if anyone has any ideas?

i tried to use the buffer to stop this and it doesnt work, im probly doing somthing stupid.

any ideas?
CHEERS
ASH

//////////////////////////////////////
// //
// Ashley Kay's Java Applet //
// Version 1 //
// //
// Duck Shoot Game //
// //
//////////////////////////////////////

import java.applet.*;
import java.awt.event.*;
import java.awt.*;

public class duckShoot extends Applet implements ActionListener
{
    Image image, duckpic;

    private Graphics gBuffer;
    private Image Buffer;

    DUCK1 duck1=null;
    T2 t2=null;

      public void init()
        {
                //create graphics buffer, the size of the applet
                Buffer=createImage(600,400);
                gBuffer=Buffer.getGraphics();
        }





    public void start()
    {
        duckpic=getImage(getDocumentBase(), "duckfamily.gif");
        image=getImage(getDocumentBase(), "lake.jpg");
        duck1=new DUCK1(this);
        duck1.start();
        resize(640,480);
        repaint();

        t2=new T2(this);
        t2.start();
    }

    public void stop()
    {
        if(duck1!=null)
            duck1.stop();
        if(t2!=null)
            t2.stop();
    }

    class DUCK1 extends Thread
{
    duckShoot app;
    int x;

    //pass reference to Applet
    DUCK1(duckShoot parent)
    {
        app=parent;
    }

    public void run()
    {
    //method loops forever if thread exsists, other processes can run aswell
        while(true) {
            if(x++>600)
                x=0;
            app.repaint();
            try{Thread.sleep(10);}catch(InterruptedException e){}
        }
    }
}

    class T2 extends Thread
{
    duckShoot app;
    int x;

    //pass reference to Applet
    T2(duckShoot parent)
    {
        app=parent;
    }

    public void run()
    {
    //method loops forever if thread exsists, other processes can run aswell
        while(true) {
            if(x++>600)
                x=0;
            app.repaint();
            try{Thread.sleep(1);}catch(InterruptedException e){}
        }
    }
}

    public void actionPerformed(ActionEvent e)
    {


    }

     public void update(Graphics g)
        {
                paint(g);
        }

    public void paint(Graphics g)
    {
        g.drawImage(image, 0,0,this);
        g.drawString("Score : ", 5, 20);
        g.drawImage(duckpic,duck1.x, 300,this);
        g.drawImage(duckpic,t2.x, 200, this);
    }
}


__________________
My new web design domain
www.askmultimedia.co.uk
 
Old May 11th, 2004, 05:14 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

has anyone any ideas on this flicker problem please??:)
cheers
ASH

 
Old May 11th, 2004, 06:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have a look at this url on double buffereing:

http://www.ryerson.ca/~dgrimsha/cour...animation.html

Cheers

Martyn





Similar Threads
Thread Thread Starter Forum Replies Last Post
Flickering image transitions in javascript hericles Javascript How-To 3 July 19th, 2007 04:58 PM
MDI children flickering during opening form vs2003team General .NET 0 December 12th, 2005 08:10 AM
how to prevent image flickering? galatea C# 1 March 12th, 2005 01:09 PM
How to avoid flickering of controls on CFormview lmadhavi Visual C++ 1 October 4th, 2004 03:00 AM
Refresh a page without the flickering effect pigtail Classic ASP Basics 12 April 5th, 2004 01:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.