Why the ball won't come out?

hi, in the following code there are two lines that each creates a Ball instance. But the line commented with "ball one" won't display a ball on the frame, however the line commented with "another ball" can do.
Totally confused!
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.lang.*;
public class BouncerFrame extends JFrame {
       JPanel canvas;
    public BouncerFrame()
       setSize(200,300); 
       setVisible(true);
       Container contentPane = getContentPane();
       canvas = new  JPanel();
       contentPane.add(canvas);
       JPanel p = new JPanel();
      Ball b = new Ball(canvas);// ball one
      JButton button = new JButton("start");
      p.add(button);
      button.addActionListener(new ActionListener()
                              { public void actionPerformed(ActionEvent ae)
                                  Ball ball = new Ball(canvas);// another ball
     contentPane.add(p,"South");
    public static void main (String [] args)
        BouncerFrame bf = new BouncerFrame();
        bf.show();
    class Ball
       private JPanel box;
       private static final int XSIZE = 10;
       private static final int YSIZE = 10;
       private int x = 10;
       private int y = 10;
       private int dx = 2;
       private int dy = 2;
        public Ball(JPanel b)
            box = b;
            Graphics g = box.getGraphics();
            g.setColor(Color.black);
            g.fillOval(x, y, XSIZE, YSIZE);
            g.dispose();
   

Don't know exactly why but this should work:
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.lang.*;
public class BouncerFrame extends JFrame {
JPanel c;
public BouncerFrame()
setSize(200,300);
setVisible(true);
Container contentPane = getContentPane();
c = new JPanel();
contentPane.add(c);
JPanel p = new JPanel();
JButton button = new JButton("start");
p.add(button);
button.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent ae)
Ball ball = new Ball(c, 20, 20);// another ball
contentPane.add(p,"South");
public static void main (String [] args)
BouncerFrame bf = new BouncerFrame();
bf.show();
Ball ball1 = new Ball(bf.c);// first ball
class Ball
private JPanel box;
private static final int XSIZE = 10;
private static final int YSIZE = 10;
private int x = 10;
private int y = 10;
private int dx = 2;
private int dy = 2;
public Ball(JPanel b)
box = b;
Graphics g = box.getGraphics();
g.setColor(Color.black);
g.fillOval(30, 30, XSIZE, YSIZE);
g.dispose();
public Ball(JPanel b, int x, int y)
box = b;
Graphics g = box.getGraphics();
g.setColor(Color.red);
g.fillOval(x, y, XSIZE, YSIZE);
g.dispose();

Similar Messages

  • My iPhone 4 worked fine yesterday an today the sound won't come out of the speakers from music and videos but worked on earphones and without earphones all I can hear is when Someone's calling me

    Idk what I did

    I got it out!
    Here is how.
    None of the Apple-suggested ways worked. However, before totally giving up I started Roxio Popcorn and pressed the big eject button on it. It came out effortlessly!
    So, I thought "Weird..."
    I put the CD back in and reproduced my original problem. I got it out just as easily using Roxio Popcorn Eject feature.
    So, I then thought "Maybe it is the disk?" There is nothing wrong with the disk as far as I can tell. It is perfectly round, has a smooth label-side surface. It is not even a label, it is a standard software install disk you buy in stores.
    I inserted a different disk. The mini mounted it, I browsed it, and then ejected it by dragging it to trash. Worked fine.
    I tried a few other disks.
    The drive seems to work fine.
    Maybe that CD is cursed, I dunno. I tried that disk in my PowerBook and it works fine there.
    Who knows ?
    I am still backing up my hard drive as I type this message in case I need to take it to the store.

  • My iMac goes into sleep mode, won't come out until I unplug and replug the computer then hit the power button. Just hitting the power button alone won't restart the iMac.

    My Imac goes into sleep mode but won't come out.  The keyboard/mouse won't rouse it and the power button won't do it either.  I have to unplug the computer, re-plug it in and then hit the power button.  Help?

    I looked around the internet and found an old post that seems to have solved the problem.  I had a relatively new USB port (powered) that I unplugged and, ta da, the problem disappeared.  I'm not sure why this happens (I'm not a tech person) but it seems like this should have been worked out in testing somewhere.

  • How do I eject a CD that won't come out of the optical drive.

    How do I eject a CD that won't come out of the optical drive on a MacBook Pro . I have tried the ejcct key on the keyboard. There is no longer an eject disk on the drop down menus. Any ideas...?

    reboot while holding down the mouse/trackpad button until the disc ejects.

  • Why does my scanned docs. come out with all colored lines on it after going thru the top feed try?

    why does my scanned docs. come out with all colored lines on it after going thru the top feed try?

    hi there,
    could you provide the community with a little more information to help narrow troubleshooting? Things like your printer model and your operating system help out a lot.
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

  • Why does a blank sheet come out of the printer first and then the sheet to be printed? HP d135 printer.

    When I try to print from a web page using Firefox, the page usually does not print in the correct format and I always get extra blank pages. Usually the first page that comes out it blank. I'm using a HP d135 All-in-one printer. This problem does not happen when I use Explorer. Does anyone have a fix for this printing problem? Thanks for any help you can provide.
    == This happened ==
    Every time Firefox opened
    == I loaded Windows 7

    @paddyv, Welcome to the Community!
    You should have the option in the program you're printing from, to change the page order. Check the settings in the program.
    If you cannot find the options, please let me know which program and operating system you're running and I will have a look in to this for you.
    Best wishes
    R a i n b o w 7000I work on behalf of HP
    Click the “Kudos Thumbs Up" at the bottom of this post to say
    “Thanks” for helping!
    Click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution!

  • I have a brand new iPad newest version. Wifi. The messaging won't send out but I receive messages from others. What is wrong?

    I have the newest version of the iPad (3rd generation) with wifi. The messaging won't send out but I'm receiving messages from others when I'm using it. They also come through on my iphone at the same time. But I can't send them out on the iPad. I tried someone's suggestion of changing the DNS to 8.8.8.8 and that did not work to fix it. What is wrong with this thing?  Thank you in advance for your help.

    Are you trying to send a message to a cell number or an email address?  iPad does MMS, not SMS, meaning it can't send a message to a number.  It can send a message to an email address........

  • IPod Touch 3G in DFU Mode and won't come out

    Hello,
    My daughter's iPod Touch 3G appears to be in DFU mode, but won't come out. The screen is completely black, and when I attach it to the computer, it comes up with the message "iTunes had detected as an iPhone in recovery mode. You must restore this iPhone before it can be used with iTunes." When I hit the restore button, I receive the error message "software for this iPhone is not currently available. Make sure you have the latest version of iTunes and try again."
    I've seen this message posted several times in the forum, and I have tried all the troubleshooting tips offered by Apple Support and in the answers to some of the questions. I am a Systems Engineer, so I consider myself pretty technically savvy. These are the steps I have followed so far:
    1) Completey removed and reinstalled iTunes according to the instructions provided by Apple.
    2) Downloaded the firmware for both the 3G and IOS4 from http://www.felixbruns.de/iPod/firmware/ and attempted a manual install - when I do this, I receive the error message, "the iPhone "iPhone" could not be restored because the firmware is incompatible"
    3) Downloaded RecBoot to attempt to exit recovery mode, but it does not appear to be detecting the iPod.
    4) Attempted to exit and re-enter DFU mode several times to no avail.
    5) Called Apple Express Lane and was willing to pay the 1 time phone support charge, however the agent told me that he could not help me, and that I needed to take the iPod into an Apple store (the iPod is 190 days out of warranty).
    My last effort is to try the install from another PC. So, prior to taking the iPod into the store, I was wondering if anyone has had any success other than the steps I have tried above. I'm appreciative for any assistance anyone is able to provide.
    Message was edited by: kander1625

    Check the model number on the back, "A1318" = 3G, "A1288" = 2G. If it truly is a 32GB 3G Touch, then you're going to have a rough time going back to an iOS version earlier than the current release (4.3.1, available from iTunes). The iOS packs you get from the site you mention are not "signed" and you probably won't be able to install them ... I think 2G owners have better luck with those "unofficial" versions.
    So, if you have a 3G, your best bet is to erase (or move) all earlier iOS versions and let iTunes download a fresh copy of 4.3.1 for the iPod -- no need to go to a 3rd party site. If you have a 2G, then the latest version you can install is 4.2.1, which is also available from iTunes. To increase your odds of this working out, you might temporarily disable any AV software and firewall(s).

  • Sound no longer comes out of the headphones but will come out of the speakers on a m6-1035dx.

    I am using Windows 7 64-bit on an HP Pavilion m6-1035dx.  Sound still comes out of the main speakers but won't come out of the headphones.  I tried the audio troubleshoot buttom and it couldn't detect the problem.  I also tried two headphones and neither work.  I didn't make any changes to my computer or really touch my computer from when it went from working to not working. 
    This question was solved.
    View Solution.

    Take a look throught this HP document and see if it help:
    http://h10025.www1.hp.com/ewfrf/wc/document?docname=c01912228&lc=en&cc=us&dlc=en
    Reminder: Please select the "Accept as Solution" button on the post that best answers your question. Also, you may click on the white star in the "Kudos" button for any helpful post to give that person a quick thanks. These feedback tools help keep our community active, so you receive better answers faster.

  • Sound no longer comes out of the speakers but will come out of the headphones on a m6-1035dx

    I am using Windows 7 Home Premium 64-bit on an HP Pavilion m6-1035dx. Sound still comes out of the headphones but won't come out of the main speakers. I tried the audio troubleshoot buttom and it couldn't detect the problem. I also tried two headphones and neither work. While i was trying to test sounds on skype application I could hear the sounds on speakers for a very short time. Please Help!!

    Hi,
    Try the following.
    First, temporarily uninstall Skype and when this has completed, restart the notebook.
    Next, download the IDT Audio installer on the link below and save it to your Downloads folder.
    http://ftp.hp.com/pub/softpaq/sp56501-57000/sp5695​3.exe
    When done, open windows Control Panel, open Device Manager and open up Sound, Video and Game Controllers.  Right click the IDT device and select Uninstall - you should also get a prompt to remove the current driver, tick the box to allow this and then proceed with the uninstall.
    When complete, shut down the notebook, unplug the AC Adapter and then remove the battery.  Hold  down the Power button for 30 seconds.  Re-insert the battery and plug in the AC Adapter.
    Tap away at the esc key as you start the notebook to enter the Start-up Menu.  Select the Bios option ( usually f10 ).  Press f5 to load the defaults ( this is sometimes f9, but the menu at the bottom will show the correct key ), use the arrow keys to select 'Yes' and hit enter.  Press f10 to save the setting and again use the arrow keys to select 'Yes' and hit enter.
    Let Windows fully load, then open your Downloads folder, right click on the IDT installer and select 'Run as Administrator' to start the installation.  When this has completed, restart the notebook again.
    If it now works Ok, reinstall Skype
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • Toner won't come out LaserJet Pro 400 MFP M425

    toner won't come out LaserJet Pro 400 MFP M425. It's stuck inside.

    I am sure it is stuck on the right side.  Odds are also that it is an aftermarket toner and not an hp original.  That said it will not be easy to remove.  You will have to do a google search for the service manual.  The right side cover needs to come off and it is not easy since the back, top and control panel need to come off.  Once you have the right side cover off you will see a big while gear behind the metal plate that holds the gear assembly to the right side.  You need to turn that gear by hand a little and it should free up the toner to come out.  When you remove the toner you will see a sort of bell housing metal piece that hangs on the right side of the toner.  That assembly fits down the right side and locks into the mech that turns the toner drum.  If that piece has defect it gets stuck.  Good Luck.  First thing I would try is to unplug the printer, then plug the printer back in and let it come to ready and open the door to see if the toner now comes out.  Sometimes turning the printer off and then back on will turn that gear by itself and free that piece.

  • Jail-broken iPhone 4S won't come out of recovery mode after attempted ios 7 update

    So I've had my jail-broken iPhone for a while and decided to go for the ios 7. After deleting 200 songs, 400 pictures & videos, and countless apps and other useless data to get the necessary free space to upgrade, I was finally able to download it. It went into recovery mode (showed the iTunes logo and the USB cord) shortly afterward. I plugged in my iPhone to my laptop, iTunes came up, but as I tried to restore the phone to upgrade to the ios 7, an error appeared saying the "iPhone software update server could not be contacted or is temporary unavailable". I've tried a LOT of stuff, from simply restarting my laptop to trying DFU mode like 200 times, and it keeps saying the same thing. Now I'm basically phoneless because it won't come out of recovery mode.
    Does this have anything to do with it being jailbroken and not backed up prior to attempting to upgrade? Please help!

    Yes, it is directly related to j'breaking it.  And as such, you will get no further support from Apple and we cannot help you either.  Use an internet search to try to find a solution elsewhere.

  • New Mini - Firewire plug is stuck and won't come out

    Hi,
    This is a virtually new Mac Mini; A firewire plug from my 20" Cinema display is stuck in the firewire port and won't come out. (I'm trying to disassemble this mini to move to another location.)
    I'm trying very hard not to pull too hard because I don't want to damage the firewire port. But I don't know what to do - it's just stuck and won't come out.
    Any ideas? Many Thanks,
    Frank B.

    Well, I finally got it out after fiddling with it, and walking away several times. I had to make sure I didn't damage it, so I approached it very gingerly.
    How did I get it out? It's amazing what actually worked. What worked was grasping ONLY the firewire chord about 1 to 2 inches away from the plug and pulling Only on the chord straight out.
    Doing it this way, it popped out with very little resistance. Strangely, the Apple Cinema Display firewire plug almost seems to click when you plug it in.
    So I immediately tested a generic firewire plug (non-Apple related) and it plugged in and pulled out with no problems or resistance whatsoever.
    "This completes my test of the Apple Cinema Display Firewire plug." (a joke there)

  • Ink black won't come out printing my tax filing.

    I was gonna plan to do tax filing and needed to print out but ink black won't come out... i have to clean cartidige with tissue paper with alcohol... but won't working... black ink appers half plently of more ink inside. What I am going to do with that?
     Please let me know asap! Thank you. 

    Hi @deafchubbbear77,
    Welcome to the HP Forums!
    I'll do my best to help with your Deskjet 3052a not printing black ink
    Please start with the steps within this Fixing Print Quality Problems for the HP Deskjet 3050A (J611) All-in-One Printer Series document.
    If that doesn't seem to do the trick you may want to try cleaning the cartridge contacts, but make sure to just use water. Alcohol will dry out the contacts and may cause further problems in the future.
    If that still doesn't work, that black cartridge may need to be replaced. To see if it's eligible for replacement, contact our technical support team via phone and inquire.
    Let me know how things go for you
    Please click “Accept as Solution ” if you feel my post resolved your issue, as it will help others find the solution faster
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    **MissTeriLynn**
    I work on behalf of HP

  • I've got music on my 4s that I can't get out of my phone. I've deleted it from ITunes and tried to manually and automatically remove (sync) and it won't come out of my phone It's gone from ITunes

    I've got music on my 4s that I can't get out of my phone. I've deleted it from ITunes and tried to manually and automatically remove (sync) and it won't come out of my phone It's gone from ITunes

    Well the iPod is supposed to be synced from YOUR iTunes music library, if you used other means to put music on there then the iPod is going to sync to only what's on your itunes music library when you connect it.
    You need to put the files into itunes.
    Far as your other issues, sounds like the drive is dying.
    Check this support article for assistance
    https://support.apple.com/kb/TS2380
    http://reviews.cnet.com/8301-13727_7-10329819-263.html
    search online for that number.

Maybe you are looking for

  • How to find out javascript application pathname?

    Hi all, I need to find out the javascript(.js) fileName and pathName via scripting. For example if i run the script from the outside of the illustrator location (c:\script\sample.js).  I need to find out the location of the scripting file(application

  • Problems displaying french special characters

    Hello, we are developing a multi-lingual WebDynpro application. The languages are set correct and the translation for all parts (portal, xls-files) works fine. Except the correct displaying of WebDynproResourceBundle-files. Example: We use the french

  • Internal table - select if in range ?

    Hello ABAP Experts, I have a internal i_gl_account table which has some of the following fields: glacctfrom, glacctto, flag i have to select a record from this internal table based on a fixed gl_account_fix. i cannot write this statement read table i

  • Last login details to a transaction

    Hi   Is there any table or any function module which stores the last login details of a user into a particular transaction code. For ex. i want to know the last login details of a user to the transaction code SBWP or SO01. Regards Haritha

  • Custom 403 http-error page

    Hi, one of our http-server-listener is running with ssl-client-certificate-required. If the client doesn't send its certificate to the server, we get a message: "Forbidden Your client is not allowed to access the requested object." How can we customi