Why does it come out as a line instead of a moving ball?

I wish to have a moving ball, but got a growing line, anybody can let me know how to solve it?
Thanks
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.lang.*;
public class Bouncer extends javax.swing.JApplet implements Runnable {
    /** Creates a new instance of Bouncer */
    public Bouncer() {
    int rectW, rectH, rectPosX, rectPosY;
    int ballW, ballH, ballPosX, ballPosY, dx, dy;
    Thread ballThread;
    public void init()
        rectW = 5000;
        rectH =5000;
        rectPosX = 0;
        rectPosY = 0;
        ballW =10;
        ballH = 10;
        ballPosX =20;
        ballPosY = 20;
        ballThread= new Thread(this);
        ballThread.start();
    public void paint(Graphics g)
     g.drawRect(rectPosX, rectPosY, rectW, rectH);
     g.drawOval(ballPosX, ballPosY, ballW, ballH);
     g.setColor(Color.black);
     g.fillOval(ballPosX, ballPosY, ballW, ballH);
     g.dispose();
    public void move()
       dx =2;
       dy=2;
      ballPosX += dx;
      ballPosY += dy;
      repaint();
    public void run() {
        while((ballPosX < rectPosX + rectW) && (ballPosY < rectPosY + rectH))
            try
                ballThread.sleep(100);
            catch(InterruptedException e)
            {e.getMessage();}
            move();
}

OK, were you trying to use drawRect() to erase the ball? That won't work since the new ball might not be in the same rectangle as the old one. Try this:public void paint(Graphics g)
    // Erase old ball
    // Note: bkgdColor should have already been set
    // to your background color (probably white)
    g.setColor(bkgdColor);
    g.fillOval(ballOldPosX, ballOldPosY, ballW, ballH);
    // Draw new ball
    // Note: fgndColor should have already been set
    // to your foreground color (probably black)
    g.setColor(fgndColor);
    g.fillOval(ballPosX, ballPosY, ballW, ballH);
    g.dispose();
}

Similar Messages

  • When adjusting the audio volume in a selected region, why does it give me a curved line instead of straight and why cant I change it like i can with a fade in our out?

    When adjusting the audio volume in a selected region, why does it give me a curved line as a transition instead of straight, and why cant I change the fade shape like i can with a fade in our out? When I slide thet volume all the way down it makes a very abrupt down curve. It's audibly noticdible.
    Thank you.

    Use the range selection tool and select the portion of the clip you want to change the volume on. Drag the volume line down and FCP will create keyframes which you can adjust as you want to get a fade shape.

  • Why does text come out looking like junk?

    I have a scanned copy of my college diploma and an award from Phi Theta Kappa Honor Society. All the text on these documents come out looking like symbols and individual letters?

    Good day,
    Could you share your file with us via the File Conversion Issue form?
    Please be sure to reference this thread in your description of the issue.
    Kind regards,
    David
    Adobe Systems

  • Why does amplitude come out as zero?

    Hi,
    I want to measure peak to peak of a square signal (0.1- 2Vac). I generate and aquire the signal using a USB-6008.
    I have tried to do this in various ways as you can see in the attachments, but all I get is zero. The signal is being read perfectly.
    Any idea what is wrong?
    Heidi
    Solved!
    Go to Solution.
    Attachments:
    Aquire.vi ‏118 KB
    Generate.vi ‏74 KB

    heididebwil wrote:
    I have tried to do this in various ways as you can see in the attachments,
    I only see one way, not various, in you attachment. Please explain.
    heididebwil wrote:
    ..., but all I get is zero. The signal is being read perfectly.
    How can it be zero (what you don't want) and read perfectly (what you want) at the same time. Please explain.
    (Sorry, I don't have DAQmx installed, so I cannot see your express configurations)
    Are you sure the device name is set correctly? How are you running this? Why are none of you error out terminals wired, e.g. even to an indicator.
    LabVIEW Champion . Do more with less code and in less time .

  • Why does this come out when I what to buy something. "MZcommerce.creditbalancemismatch.mobile_message"

    I'm trying to buy on iTunes, a song but it doesn't let me.
    This pops out.
    MZcommerce.creditbalancemismatch.mobile_message

    You know what a just did. Ir worked.
    Sign out and press on the buy botton and when it ask you. Create account or use existing apple account. Yo chose existing apple account an login and it will start to download.
    I hate doing it buy whatever it works.

  • HT1665 Why does music come out muddled and echoing in alarm mode when the iPhone is connected to the Bose SoundDock lll?

    There is a very unique problem with the iPhone 5 and iPad mini when connected to the Bose SoundDock III.
    In normal music playback, music sounds great coming out of the Bose SoundDock, but, when a song is chosen for the Apple Alarm App and turns on when the alarm goes off, the music sounds terrible.  It reverberates, echoes, is muddled, sounds messy.
    What is so odd about this is the same sound coming out of a speaker-device connected to the phone's headphone jack sounds perfect, and as intended.
    It only has this issue when it is in alarm mode and it's connected via the lighting port connector.
    Is this an Apple software glitch that wasn't researched fully or a manufacturing defect on the Bose end?
    I've tried a couple Bose systems so it isn't peculiar to one SoundDock.
    What are your thoughts?

    Check Settings > General > Cellular > Cellular Data and make sure it's "On".

  • Why does Facebook come out magnified when I open it? (Huge Font)

    All the other sites open in regular size font as usual except Facebook, it is magnified or zoomed when I open it

    hello bluyacht, try to press ctrl+0 ('zero') while you're on the page in order to reset the zoom level for that page or in case this doesn't work also go through the other common troubleshooting steps at [[Websites look wrong or appear differently than they should]]

  • Why does the pen tool remove previous line when I add new anchor points??

    Why does the pen tool remove previous lines??
    Video here:  http://youtu.be/8AmPUkD88h0 
    It removes the hairline on the face, when I add more anchor points. Why? And how do I correct it?

    The ins and outs of the new and changed behaviors in the re-engineered pen tool have been disussed here on this forum and I'm sure a little detour to the help files will also shed some light on this...
    Mylenium

  • Why does firefox time out so often? slows down my working

    Why does firefox time out so often. I can be in the middle of something and it just stops. did it as I am trying to write this note. very frustrating! It either times out or freezes. the former happens more often. I can be on the web or on yahoo mail.

    The default of the pref network.http.max-connections has been increased from 30 to 256 in Firefox 6+ versions.
    Try to decrease the value of the pref <b>network.http.max-connections</b> from 255 to a setting like 30 as used in Firefox 3 versions.
    *https://support.mozilla.com/kb/Firefox+never+finishes+loading+certain+websites
    See also:
    * http://blog.bonardo.net/2011/09/30/is-your-firefor-freezing-at-regular-intervals
    * Places Maintenance: https://addons.mozilla.org/firefox/addon/places-maintenance/

  • When does yosemite come out?

    I live in ireland and I was just wondering when does yosemite come out here? I was watching the apple keynote just there and it said it was coming out today but I can't find it on the app store. Can someone please help me?

    At 2:36 pm CDT it is showing up on the Apple page as "Upgrade Now" yet when you click on that... it opens up your App Store and gives the message that the program is not available in the US store. Not sure why, but that's what I'm getting here!   :-)   Patience is a virtue... but often difficult with new Mac stuff. Lol.

  • Why does ical print out starting tuesday?

    Why does ical print out staring the week on tuesday?
    Maybe the week starts one day later for the Yosemite dev team, but certainly not in my neck of the woods.
    The actual print out also looks nothing like the new matt and  'flat' graphic style of Yosemite.
    I suggest you start on monday next week and sort these issues out.
    Sunny

    For many people that is the correct option. If you think it should be different, tell Apple, as they aren't listening here.

  • External hard drive does not come out in desktop

    greetings! whenever i plug in an external hard drive or a USB flash disk through usb, it does not come out in the desk top. before, it used to come out, now it doesn't. i am still using the exact macbook. i think i touched something in the settings. please help

    Go to finder and choose preferences under finder in the menu bar. Now check and see if under General you have the choices clicked of what you want to show on the desk top.

  • I have a disk in my mac and came not get it out?  I use the command E key to eject but it does note come out?

    I have a disk in my mac but it does note come out useing command e to eject? how do i get it out or do I have to get it jixed?

    Force eject a stuck cd/dvd
    First try the normal methods to remove the disc. Drag its icon to the Trash can in the Dock or select 'Eject' from the File menu.
    If you are running a virtual machine, e.g. VMFusion, ensure that the CD is disconnected from the virtual machine. This will sometimes allow the CD to now show up in Mac OS X.
    Shut down the computer and start up whilst holding down the mouse button. This may take some time, but keep your finger on the mouse button right up until the disc comes out or the log-in screen has appeared.
    If you have Toast Titanium installed on your computer, choose EJECT DISC from the menubar.
    Sometimes you can successfully use the eject disc button in iTunes even if the disc is not visible to the Finder
    Open Disc utility and choose the disc you wish to eject in the left-hand pane, then click on the Eject button.
    Some Macintoshes have a paperclip hole that you can insert a straightened paperclip into, manually triggering the eject mechanism.
    Open Terminal and type "drutil tray eject" to eject the disc/tray, and "drutil tray close" to close the tray.
    If your computer has an eject button on the keyboard, restart the computer holding down the Option key. When the startup disk selection screen appears, let go of the option key and press the keyboard's eject button.
    Source: http://guides.macrumors.com/Force_Eject_a_Stuck_CD_or_DVD

  • Why does it come white when i take a picture on my Iphone4s? it's new, I bought it before 2 weeks ago. what can I do?

    why does it come white when i take a picture on my Iphone4s? it is not all of the pictures which becomes white, but some of them and it is not because i used flash. the phone is new as well , I bought it before 2 weeks ago. what can I do? please need help.

    First step in troubleshooting is to reset your device: hold down the home button along with the sleep/wake button until the screen goes black and you see the Apple, then let go. (No data loss)

  • Why does siri come on by itself while it sits on the table no one touching it?

    why does siri come on by itself while it sits on the table no one touching it?

    michael jfromtaunton wrote:
    why does siri come on by itself while it sits on the table no one touching it?
    If you're not running iOS 8 as you describe you are not, and Siri keeps coming on, this could be a hardware failure of the Home Button.
    Try these steps:
    Basic Troubleshooting Steps when all else fails
    - Quit the App by opening multi-tasking bar, and swiping the App upward to make it disappear.  (For iOS 6 older, hold down the icon for the App for about 3-5 seconds, and then tap the red circle with the white minus sign.)
    - Relaunch the App and try again.
    - Restart the device. http://support.apple.com/kb/ht1430
    - Reset the device. (Same article as above.)
    - Reset All Settings (Settings > General > Reset > Reset All Settings)
    - Restore from backup. http://support.apple.com/kb/ht1766 (If you don't have a backup, make one now, then skip to the next step.)
    - Restore as new device. http://support.apple.com/kb/HT4137  For this step, do not re-download ANYTHING, and do not sign into your Apple ID.
    - Test the issue after each step.  If the last one does not resolve the issue, it is likely a hardware problem.

Maybe you are looking for

  • Populate data in dynamic internal table

    Hi ppl, I have a requirement where I need to display certain fields in the report output. The output contains 8 fixed fields (common for all rows in output) and some dynamic fields (number of column varies with rows) which will be determined at runti

  • ODBC connect to SQL Server 2005 from Oracle 10.2.0.3 32bit Linux

    I’m unable to establish a connection from Oracle 10.2.0.3 32bit Linux to SQL Server 2005. The ODBC driver is the 32bit DataDirect 5.3 drivers and when I do a status on the listener it does have a handler for SQLDB Any help is appreciated. Received th

  • Stomp bridge not working in GlassFish V3

    Hello, this is a test report for the OpenMQ Stomp Bridge on Windows Vista: * downloaded http://download.java.net/glassfish/v3/release/glassfish-v3-windows.exe * installed at C:\glassfishv3-test2 * started GlassFish using startserv.bat * deployed imqu

  • Passing Item Number as a Parameter takes long time,need to make it optional

    Hi, I am trying to pass Inventory Item as a parameter in the discoverer report and it is taking long time to query the results. I am not sure how to make a parameter optional (Not Required) Please advice Thanks, user12048986 Edited by: user12048986 o

  • How would I copy,paste, and erase in Adobe Photoshop CS5?(Easy points)

    Please explain the steps I would do in order to complete these tasks.Thank you. *The reason I am asking this is because customer service is unvailable to me and when I try to accomplish what I seem to be erasing,copying,and or pasting my actions end