Balls don't move in bouncing balls game.Please Help !?

I want to repaint the canvas panel in this bouncing balls game, but i do something wrong i don't know what, and the JPanel doesn't repaint?
The first class defines a BALL as a THREAD
If anyone knows how to correct the code please to write....
package ****;
//THE FIRST CLASS
class CollideBall extends Thread{
    int width, height;
    public static final int diameter=15;
    //coordinates and value of increment
    double x, y, xinc, yinc, coll_x, coll_y;
    boolean collide;
    Color color;
    Rectangle r;
    bold BouncingBalls balls; //A REFERENCE TO SECOND CLASS
    //the constructor
    public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c, BouncingBalls balls) {
        width=w;
        height=h;
        this.x=x;
        this.y=y;
        this.xinc=xinc;
        this.yinc=yinc;
        this.balls=balls;
        color=c;
        r=new Rectangle(150,80,130,90);
    public double getCenterX() {return x+diameter/2;}
    public double getCenterY() {return y+diameter/2;}
    public void move() {
        if (collide) {
        x+=xinc;
        y+=yinc;
        //when the ball bumps against a boundary, it bounces off
        //bounce off the obstacle
    public void hit(CollideBall b) {
        if(!collide) {
            coll_x=b.getCenterX();
            coll_y=b.getCenterY();
            collide=true;
    public void paint(Graphics gr) {
        Graphics g = gr;
        g.setColor(color);
        //the coordinates in fillOval have to be int, so we cast
        //explicitly from double to int
        g.fillOval((int)x,(int)y,diameter,diameter);
        g.setColor(Color.white);
        g.drawArc((int)x,(int)y,diameter,diameter,45,180);
        g.setColor(Color.darkGray);
        g.drawArc((int)x,(int)y,diameter,diameter,225,180);
        g.dispose(); ////////
    ///// Here is the buggy code/////
    public void run() {
        while(true) {
            try {Thread.sleep(15);} catch (Exception e) { }
            synchronized(balls)
                move();
                balls.repairCollisions(this);
            paint(balls.gBuffer);
            balls.canvas.repaint();
//THE SECOND CLASS
public class BouncingBalls extends JFrame{
    public Graphics gBuffer;
    public BufferedImage buffer;
    private Obstacle o;
    private List<CollideBall> balls=new ArrayList();
    private static final int SPEED_MIN = 0;
    private static final int SPEED_MAX = 15;
    private static final int SPEED_INIT = 3;
    private static final int INIT_X = 30;
    private static final int INIT_Y = 30;
    private JSlider slider;
    private ChangeListener listener;
    private MouseListener mlistener;
    private int speedToSet = SPEED_INIT;
    public JPanel canvas;
    private JPanel p;
    public BouncingBalls() {
        super("****");
        setSize(800, 600);
        p = new JPanel();
        Container contentPane = getContentPane();
        final BouncingBalls xxxx=this;
        o=new Obstacle(150,80,130,90);
        buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
        gBuffer=buffer.getGraphics();
        //JPanel canvas start
        canvas = new JPanel() {
            final int w=getSize().width-5;
            final int h=getSize().height-5;
            @Override
            public void update(Graphics g)
               paintComponent(g);
            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                gBuffer.setColor(Color.ORANGE);
                gBuffer.fillRect(0,0,getSize().width,getSize().height);
                gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
                //paint the obstacle rectangle
                o.paint(gBuffer);
                g.drawImage(buffer,0,0, null);
                //gBuffer.dispose();
        };//JPanel canvas end
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
        addButton(p, "Start", new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                CollideBall b = new CollideBall(canvas.getSize().width,canvas.getSize().height
                        ,INIT_X,INIT_Y,speedToSet,speedToSet,Color.BLUE,xxxx);
                balls.add(b);
                b.start();
        contentPane.add(canvas, "Center");
        contentPane.add(p, "South");
    public void addButton(Container c, String title, ActionListener a) {
        JButton b = new JButton(title);
        c.add(b);
        b.addActionListener(a);
    public boolean collide(CollideBall b1, CollideBall b2) {
        double wx=b1.getCenterX()-b2.getCenterX();
        double wy=b1.getCenterY()-b2.getCenterY();
        //we calculate the distance between the centers two
        //colliding balls (theorem of Pythagoras)
        double distance=Math.sqrt(wx*wx+wy*wy);
        if(distance<b1.diameter)
            return true;
        return false;
    synchronized void repairCollisions(CollideBall a) {
        for (CollideBall x:balls) if (x!=a && collide(x,a)) {
            x.hit(a);
            a.hit(x);
    public static void main(String[] args) {
        JFrame frame = new BouncingBalls();
        frame.setVisible(true);
}  This code draws only the first position of the ball:
http://img267.imageshack.us/my.php?image=51649094by6.jpg

I'm trying to draw everything first to a buffer:
buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
gBuffer=buffer.getGraphics();
The buffer is for one JPanel and then i want to draw this buffer every time when balls change their possitions(collide or just move).
The logic is something like this:
startButton -> (ball.start() and add ball to List<balls>),
ball.start() -> ball.run() -> (move allballs, paint to buffer and show buffer)
In the first class:
BouncingBalls balls; //A REFERENCE TO SECOND CLASS
In the second class:
private List<CollideBall> balls=new ArrayList();
the tames are the same but this isn't an error.
Edited by: vigour on Feb 14, 2008 7:57 AM

Similar Messages

  • After Effects SWF file appears black with no image. Only 2 layers in AE file (one that moves the other static). Please help!

    After Effects 5.5.
    I need this file as a swf but it appears black when I export.
    Only 2 layers in AE file (one that moves the other static). Please help!
    Thank you!

    Thanks for your response. Is there no other way to get the swf file to work properly from After Effects?
    What is the best way to go about using the MP4, F4V or FLV formats to save as a swf in Flash?
    Can you advise how I can save it to MP4, F4V or FLV from After Effects Creative Cloud? they don't seem to be visible (I also have creative cloud)
    Thank you very much

  • Please help, i movie is not exporting or sharing movies, it will closed unexpectedly please help?

    Please help, i movie is not exporting or sharing movies, it will closed unexpectedly please help?

    Hi Videoframe
    This was emailed to Apple Support on 23 DEc 2012 at 09:50 Eastern Australia time.
    "I continued to talk to other Apple Mac users on iMovie….Interesting to have found out that their movies were made using iDVD without any known issues as yet…Looking at the results from Apple Support Forum and Youtube, problems appears to be when NOT using iDVD. I and many others can't understand how these many technical problems were overlooked by the programmers of iMovie. One would have thought iMovie problems have been iron out prior to getting rid of iDVD. By the way when I first contacted Apple Support back on 16th Nov, I was told I need to RE-INSTALL my computer…..that I did and in the process my iDVD was removed and never was re-installed.
    May I suggest you delegate a junior person or someone string together a project consisting over near 1700 images, approx. 25mins of video footage, titles and including with and without transitions then export the project.
    I am still in the dark as to what is being done about this extended non result. I am not sure if is known by the people who is in charge of this iMovie programme. it would be nice to get some sort of feedback. Not sure if I should refer this to a third party to do the testing?? I am sure Apple's competitors would love to make a mockery of this.
    There has to be a time frame for this to end, as I and many others can't simply sit here in the dark and wait for someone to come back for a solution, this could be months or years who knows.  As you can appreciate I am not the only user anxiously waiting for a solution.
    I guess I am in a way representing other worldwide users in pursuing a solution on this matter ASAP. I therefore ask you to please make this a priority if this is at all possible.
    Many thanks."
    I've been corresponding to them since Fri 16th Nov on and off without a solution.

  • I have forgotten my password for iPod Touch 4G and it is now disabled. I tried connecting to iTunes but i haven't synced before and i need to enter the password before i can back it up so i can restore it. I don't want to lose pictures so please help!

    I have forgotten my password for iPod Touch 4G and it is now disabled. I tried connecting to iTunes but i haven't synced before and i need to enter the password before i can back it up so i can restore it. I don't want to lose pictures so please HELP!

    Disabled
    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased. That is how it works
    iOS: Forgot passcode or device disabled
    If recovery mode does not work try DFU mode.                        
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: Back up and restore your iOS device with iCloud or iTunes       
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        
    If problem what happens or does not happen and when in the instructions? When you successfully get the iPod in recovery mode and connect to computer iTunes should say it found an iPod in recovery mode.

  • "Do you want to allow the following program from an unknown publisher to make changes to this computer?" I mean....what would you do? Is it safe to click yes....(Don Don Don...*sound effect*)..please help...

    Okay everybody...so I'm on the struggle bus so I'm going from Photoshop cs6 off my old broken laptop to trying to dwn Photoshop Cs2...either way I love PS. Now when I tried downloading it for free from Adobe...succeeded...but when I went to the download folder to install it, it said "Do you want to allow the following program from an unknown publisher to make changes to this computer?" I mean....what would you do? Is it safe to click yes....(Don Don Don...*sound effect*)..please help...

    If you already have a license for photoshop cs6, why do you want photoshop cs2?
    You can just install photoshop cs6 on your new computer provided both operating systems are the same kind (both mac or both windows)
    If you don't have an install dvd for cs6, you can download photoshop cs6 from here and use your serial:
    http://helpx.adobe.com/x-productkb/policy-pricing/cs6-product-downloads.html

  • I want to check the main diffrence in Pop up block enabled and disabled.But,i don't get any difference.Would u please help me to understand the difference using one practical example of website

    I want to check the main diffrence in Pop up block enabled and disabled.But,i don't get any difference.Would u please help me to understand the difference using one practical example of website

    Here's two popup test sites.
    http://www.kephyr.com/popupkillertest/test/index.html
    http://www.popuptest.com/

  • HT1689 Can i use debit card as a payment method on app store..if not,what else?? in case i don''t have credit card...please help

    Can i use debit card as a payment method on app store..if not,what else?? in case i don''t have credit card...please help

    I don't think that debit cards are still accepted as a valid payment method - they are not listed on this page and there have been a number of posts recently about them being declined. You could try contacting iTunes support but I don't think that you will be able to use it : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page
    If you don't have a credit card then are iTunes gift cards available in your country ? They are not available in all countries and they are country-specific (they can only be used in their country of issue), so you won't be able to use those from another country.

  • My iPhoto keeps quitting unexpectedly and won't open. I don't know what to do. Please help!

    My iPhoto keeps quitting unexpectedly and won't open. I don't know what to do. Please help!

    Do you get a crash report?  If so post just the first 50 lines of it.
    OT

  • I have a 2007 macbook that is stuck on the loading page and after a while it shuts down by itself. I don't know what to do anymore please help!!!

    I have a 2007 macbook that is stuck on the loading page and after a while it shuts down by itself. I don't know what to do anymore please help!!!

    Hello Sebas4224
    Start with the article below to troubleshoot issues with your MacBook starting up and staying on. Let me know how it goes in case it does not help and I or others can assist you further.
    Mac OS X: Gray screen appears during startup
    http://support.apple.com/kb/TS2570
    Regards,
    -Norm G.

  • Hello guys i face a problem when i upgrade from iOS 4.2.1 to iOS 5.1.1  .when i upgrade i don' t found the camera app from the built in apps.when i try to install from the app store i don't  found the correct camera app .please help me .

    hello guys i face a problem when i upgrade from iOS 4.2.1 to iOS 5.1.1 on ipad 3 .when i upgrade i don' t found the camera app from the built in apps.when i try to install from the app store i don't  found the correct camera app .please help me .please give any suitable link where i find the correct camera app

    It's a built-in app, so it can't be deleted nor downloaded from the store. If you can't find it on any of your homescreens or app folders, and you can't find it via the spotlight search screen (swipe your first home screen to the right), then is it hidden by Settings > General > Restrictions > Camera being set 'off' ?
    If not then have you tried a reset to see if you can find it after the iPad has restarted ? Press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • My iPhone 5 speaker suddenly doesn't work properly!  The volume is so low I can't hear the phone ring.  I've restored and updated and done everything I can think of.  Please help!

    My iPhone 5 speaker suddenly doesn't work properly!  The volume is so low I can't hear the phone ring.  I've restored and updated and done everything I can think of.  Please help!

    Sorry, I think you got scam.
    Last thing you can try is restore as new:
    http://support.apple.com/kb/HT1414

  • I can't remove my Visa card and I don't have Money and hidden none please help me

    I can't remove my Visa card and I don't have Money and hidden none please help me

    Accepted forms of payment  >  http://support.apple.com/kb/HT5552
    Changing Account Information  >  http://support.apple.com/kb/HT1918
    If necessary... Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • I reset my iPhone 3gs by erase all data and settings. After the process i was waiting till morning but its still shows the apple logo.its been 8 hours but i don't know what to do? please help me to fix it.

    i reset my iPhone 3gs by erase all data and settings. After the process i was waiting till morning but its still shows the apple logo.its been 8 hours but i don't know what to do? please help me to fix it.

    Something has gone wrong. Force the phone into recovery mode, as described here, & restore it:
    http://support.apple.com/kb/ht1808

  • Whenever I open my notes it crashes, sending me back to my gome screen. I have tried turning my ipad off, closing it down fully, backing up my ipad... I don't know what to do. Please help.

    Whenever I open my notes it crashes, sending me back to my gome screen. I have tried turning my ipad off, closing it down fully, backing up my ipad... I don't know what to do. Please help.

    Reset it by holding the power and home buttons at the same time until you see the Apple logo, then release.  This just restarts it, you won't lose any data by doing this.

  • HT1572 My iPod shuffle is not working. It just blinks in green then orange, orange, orange, then shutdown. Don't know what to do. Please help! Thanks!

    My iPod shuffle is not working. It just blinks in green then orange, orange, orange, then shutdown. Don't know what to do. Please help! Thanks!

    According to this article, that means the Shuffle's buttons are disabled.
    iPod shuffle (2nd generation): Understanding status light behavior
    To re-enable the buttons, press and hold the Play/Pause button for about 3 seconds or until the status light blinks green three times.
    B-rock

Maybe you are looking for

  • Can you code a link between html and a particular flash page?

    Hi, I hope this question is not too confusing. I am designing a website in flash CS3 using Action script 2.0 not 3.0 and Flash Player 8. The architecture I used is as follows:  I have a menu/main page which loads the swf files of other flash pages. 

  • How to redirect a page on iweb

    Hi I have an online store @ cafepress that I built with them..Is there a way to create a page on Iweb that visitors click (the tab) and are then taken to that specific page or is there a way to embed that page into an iweb page....any help would be a

  • OBYC FI-MM configuration settings

    Hi All Experts, I was working on support project, fortunately I am getting chance to work on Implementation project. I have a little bit of idea about FI-MM intergtation furnctioanlity. Would like to have experts guidance about technically. The confi

  • Conflict with Adobe Professional while opening Adobe Interactive form

    Hello Experts, We have developed an Adobe Interactive form which is being lauched from the Portal. Every functionality is working good. Some of the users have Adobe professional on their machines and when they try to launch the Adobe Form, the form g

  • Rule based classification  errors in creating CLASSIFIER.THIS

    package body "STARDOC".classifier as procedure this is v_document     blob; v_item          number; v_doc           number; begin for doc in (select document_id, content from documents)      loop           v_document :=doc.content;           v_item:=