Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 9th, 2004, 10:53 AM
Authorized User
 
Join Date: Jan 2004
Location: Manchester, , United Kingdom.
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
Reply With Quote
  #2 (permalink)  
Old May 11th, 2004, 05:14 AM
Authorized User
 
Join Date: Jan 2004
Location: Manchester, , United Kingdom.
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

Reply With Quote
  #3 (permalink)  
Old May 11th, 2004, 06:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:05 PM.


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