JButton not working with for loop...

I am still very new to Java and am having trouble grasping it. I am trying to put together a program that paints a graphic and then each time the "Press Me" button is pressed, an oval randomly appears giving the impression that the picture is 'disappearing' a little at a time. When I run it now, 20 ovals randomly appear all at once instead of waiting for the button to be pushed. Does anyone have any advice for me on how to modify the code? Here is what I have so far...
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.awt.geom.*;
public class JEraseImage extends JApplet implements ActionListener
private ImageIcon image1 = new ImageIcon("bear.jpg");
int startPosX = 80;
int startPosY = 80;
int imageWidth = 275;
int imageHeight = 250;
Container con = getContentPane();
private JButton pressMeButton = new JButton("Press Me");
public void init()
image1 = new ImageIcon("bear.jpg");
con.setLayout(new FlowLayout());
con.add(pressMeButton);
pressMeButton.addActionListener(this);
public void paint(Graphics gr)
gr.drawImage(image1.getImage(), 80, 80, (this));
Graphics2D gr2D = (Graphics2D)gr;
pressMeButton.repaint();
gr.setColor (Color.white);
for(int count = 0; count < 20; ++count)
int x = (int) (Math.random() * imageWidth) + startPosX;
int y = (int) (Math.random() * imageHeight) + startPosY;
gr.fillOval(x, y, 50, 40);
public void actionPerformed(ActionEvent e)
Object source = e.getSource();
if(source == pressMeButton)
repaint();

Here ya go, I think this should do it:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.util.*;
import javax.swing.*;
import java.awt.geom.*;
public class Junk extends JApplet implements ActionListener
    private ImageIcon image1;
    BufferedImage bi;
    Graphics g;
    int x;
    int y;
    int startPosX = 80;
    int startPosY = 80;
    int imageWidth;
    int imageHeight;
    Container con = getContentPane();
    JButton pressMeButton = new JButton("Press Me");
    public void init()
       image1 = new ImageIcon("bear.jpg");
       bi = new BufferedImage(image1.getIconWidth(), image1.getIconHeight(), BufferedImage.TYPE_INT_RGB);
       g = bi.getGraphics();
       g.drawImage(image1.getImage(), 0, 0, null);
       con.setLayout(new FlowLayout());
       con.add(pressMeButton);
       pressMeButton.addActionListener(this);
    public void paint(Graphics gr){
        super.paint(gr);
        gr.drawImage(bi, startPosX, startPosY, this);
    public void actionPerformed(ActionEvent e)
       g.setColor(Color.WHITE);
       Object source = e.getSource();
       if(source == pressMeButton)
       for(int count = 0; count < 20; ++count)
                 int x = (int) (Math.random() * imageWidth) + startPosX;
                 y = (int) (Math.random() * imageHeight) + startPosY;
                 g.fillOval(x, y, 50, 40);
                 repaint();
}Note: I've not run this.

Similar Messages

  • Sql statement not working with for update

    Hi, iam facing an error fetch out of sequence
    when iam trying to execute a sql statement
    Statement st=con.createStatement();
    st.executeQuery(select mycolumn from table where jobno=1 for update);
    the statement works well without " for update ".
    any solutions????

    Hi,
    The fetch out of sequence error occurs usually when you are trying to read from a cursor that has no data left(like EOF).
    After executing the sql statement move the pointer to the first row (or the beginning of the resultset)
    This is actually an oracle error bearing number :ORA:01002
    Hope this helps.
    Thanks,
    Creator Team.

  • My itunes 11 Home sharing is not working with my windows 7 PC and iPad it shows up on iPad and when I go to share the music app does loading for 3 mins and crashes I am using a virgin super hub router please please please help

    My itunes 11 Home sharing is not working with my windows 7 PC and iPad it shows up on iPad and when I go to share the music app does loading for 3 mins and crashes I am using a virgin super hub router please please please help

    My itunes 11 Home sharing is not working with my windows 7 PC and iPad it shows up on iPad and when I go to share the music app does loading for 3 mins and crashes I am using a virgin super hub router please please please help

  • I bought this iPhone from Apple Retail Store for the full amount, but  it does not work with my SIM card only works with AT&T

    Hello,
    I have an iPhone 4S 32Gb White AT&T, product part No. MC921LL/A, Serial No. C39GMLPWDTDC
    I bought this iPhone from Apple Retail Store (from Fifth Avenue, NY) for the full amount. Now it does not work with my SIM card only works with AT&T. I restored the phone several times, but I have not received "Congratulations your iPhone has been unlocked". Please activate my iPhone to work with different SIM cards
    Thanks,
    Best Wishes

    When did you buy it?
    Apple did not begin selling an unlocked version of the iPhone 4S in the US until 11/11/11. I believe it went on sale only through the online store at that time. I'm not sure if it's available at retail yet.
    What you purchased was a phone without a contract commitment. It is still locked to AT&T. AT&T will NOT unlock iPhones for any reason.  Return it and get your money back, then use that to purchase an unlocked phone.

  • I bought the Keynote app for my MacBook, but when I open the application and try to install it, I get an error message saying that the application will not work with my MacBook. What gives? And, can I please request a refund? ($19.99 = a week's groceries)

    I bought the Keynote app for my MacBook, but when I open the application and try to install it, I get an error message saying that the application will not work with my MacBook. What gives? And, can I please request a refund? ($19.99 = a week's groceries).
    Thank you for your help! - I did try looking for all available specs about Keynote on the Apple iTunes website, and found nothing that could help me. HELP!

    1
    Close all iWork applications
    2
    Uninstall Keynote; this must be done with an application remover tool to delete the installation properly. Appcleaner is known to work correctly for this purpose, it is free and can be downloaded from here: Appcleaner Download
    3
    empty the trash
    4
    shutdown the Mac and restart. After the start up chime, hold down the shift key until the apple logo appears
    let the Mac complete the start up procedure completely, it will take longer than usual as the hard drive is being repaired
    5
    Reinstall Keynote by logging into the Mac App Store using download / install

  • HT4623 Why do my iPhone cords for my 5 say it is not certified and may not work with this device? It's the same cord that came with my phone. The only difference is the iOS7 update.

    Why do my iPhone cords for my 5 say it is not certified and may not work with this device? It's the same cord that came with my phone. The only difference is the iOS7 update.
    Maps took me to the completely wrong side of town for a long standing business in town.

    Hello margmcarlson,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    Troubleshooting iPhone, iPad, and iPod touch accessories
    http://support.apple.com/kb/TS2634
    Restore iPhone, iPad, or iPod touch to its factory default state. You should rarely need to use this step with an accessory issue.
    Best of luck,
    Mario

  • Need driver for canon mg 5250 as scanner is not working with version 10.7. Can you please help me to find the driver so scanner works with WIFI?

    need driver for canon mg 5250 as scanner is not working with version 10.7. Lion. Can you please help me to find the driver so scanner works with WIFI?

    Try with the latest Apple driver package for Canon (released 15th Feb):
    http://support.apple.com/kb/DL899
    This solved my problem with the printing.

  • HP B500 Wireless Bluethooth Adapter for HP Printer Not Working With Windows 8.1

    I have been using the HP BT500 bluetooth Wireless adapter to print wirelessly to my HP Officejet Pro 8500 printer.  I have been using Windows Vista, but recently upgraded to Windows 8.1.  I learned after the upgrade that the HP B500 wireless bluetooth adapter is not compatable with Windows 8.1.  I have attempted to find a driver upgrade for the B500, but there does not appear to be one available.  I have also searched the HP site and other sites in an attempt to locate an alter wireless blotth adapter to replace the B500, but have again been unable to locate one. 
    Is there a wireless bluetooth apter that will allow me to print wirelessly to my HP Office Pro 8500 from my laptop?

    Hi @Raider83,
    Welcome to the HP Forums!
    I noticed that your HP B500 wireless bluetooth adapter for your HP Officejet 8500 is not working with Windows 8.1. I am sorry to hear this but happy to look into this for you!
    I am not sure if you are using a 32-bit or 64-bit Operating System. But sometimes with Windows 8.1 you can use compatibility mode to install an older version of the driver. Which might help the situation. Here is a link to some other Windows drivers, HP bt500 Bluetooth USB 2.0 Wireless Adapter Drivers.
    Once you got a driver downloaded, follow this guide, Make older programs compatible with this version of Windows, on how to install it using compatibility mode.  It is not guaranteed to work, but it is worth a try!
    If you still need me to look for other bluetooth adapters, please respond with your printer's Product/Model Number. To find your printer's Product/Model Number follow instructions in this link. Finding Your HP Product Model Number. As there are multiple HP Officejet 8500 printers.
    Thank you for posting, and have a nice day!
    RnRMusicMan
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to say “Thanks” for helping!

  • Internal Microphone not working with Quicktime and some other apps, yet it does for Skype.

    Internal Microphone not working with Quicktime and some other apps, yet it does for Skype. 
    Microphone works fine with Quictime on another mac, so I do know how to use it. The one where it is not working (A) had an external microphone and camera attached earlier, and indeed it does work with that external microphone, but not with the internal microphone selected; and (B) had RealPlayer installed previously.
    Any suggestions, please?

    Hi,
    Download Audio driver from here.
    Intructions how to install it in Vista/Win7.
    Extract this driver with Winrar.
    Open Device manager and expand the Sound, video and game controllers section.
    Right click on Either the High Definition Audio Device if you have the generic Microsoft drivers, or the Conexant High Definition SmartAudio 221 if you have older Conexant drivers and choose "Update Driver Software..."
    Click Browse my computer for driver software, then click "Let me pick from a list of device drivers on my computer"
    Click "Have Disk..." then Browse to the folder where the drivers were extracted  .......\V64 for 64-bit Vista/Win7. Click OK.
    Select one of the "Conexant High Definition SmartAudio 221" models in the list, there will be multiple identical entries.
    Click Next, and you're done.
    I'm not sure which one from the list will work for You.
    This drivers weren't test. So if You will try them and it will work for You let us now about.
    ** Say thanks by clicking the "Thumb up" icon which is on the left. **
    ** Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue. **

  • Site list update not working with TED and Zenworks for Servers

    Product: Zenworks for Desktops 7Sp1 and Zenworks For Server/TED 7Sp1HP5
    Subject: Site list update not working with TED and Zenworks for Servers ,
    all on Linux
    Description: We have an exiting environment with 6 ZfS Servers and now we
    brought up a new Server for another location. I configured all same as on
    the other Server and the new one created all NAL-Apps at the new location.
    But in the Application Site list on the golden App is this Application
    missing. So I clicked on the Link up site list on the Distribution Screen
    in C1. On ApplicationSite list the App from the new location is missing.
    So I removed all and added the new from the new location and now i see all
    in the application site list.When I install an app on the client on the
    new location NAL is connecting alway th the same (wrong location-server
    and i get an msi error 1612 or id=53272 with path=\Wrong serverpath to
    file.
    I looked on the other tab on C1 at the golden app an I see the backlinks
    are going to all other servers without the new one. Software installation
    on other locations are ok
    Regards

    Andreas,
    I forgot to mention that you can also set the loging level on the Distributor and the Subscriber to 6. to do this at the Zenworks Server Management prompt type "setconsolelevel 6" if you want to capture this to the log file ted.log then use "setfilelevel 6"
    Next delete the Distribution from the Subscriber and then re-push the channel.
    What we are looking for here in the log is the creation of the object and the linking information about the gold object. it should look like this (not the failure part ;-))) )
    In this excerpt you will see the entry
    Golden App =
    This should be were the link is to
    You can check this both ways in the Golden App and in the Distributed Application.
    Here is a log from me that shows this info as an example of what you should be looking for.
    2008.05.29 03:35:41 [TED:Work Order In(yourserver.yes.com)] Receiving distribution: Creating new application failed,
    Subscriber Tree Name= YOUR-TREE,
    Subscriber DN = SUBSCRIBER_YOURSERVER.BRN.FL.SUBS.SUBSCRIBERS.ZSM. GRS.CBH,
    Golden App = SCRIPT-MS-HOTFIX.APP.BRN.ZENGOLD.GRS.CBH,
    Attempted AppName = SCRIPT-MS-HOTFIX.APP.BRN.HAVERHI.PALM.FL.CBH,
    error message: Failed creating SCRIPT-MS-HOTFIX.APP.BRN.HAVERHI.PALM.FL.CBH. With error message: Setting the trustee for BRN.HAVERHI.PALM.FL.CBH on the file "VOL1:\ZEN\UTILS" failed. Look in subscriber log file for more details..
    2008.05.29 03:35:41 [TED:Event Processing] Handle Event: Work order IN completed... Creating new application failed,
    Subscriber Tree Name= YOUR-TREE,
    Subscriber DN = SUBSCRIBER_HAVERHI-FLBRN1.BRN.FL.SUBS.SUBSCRIBERS.ZSM.GRS.CBH,
    Golden App = SCRIPT-MS-HOTFIX.APP.BRN.ZENGOLD.GRS.CBH,
    Attempted AppName = SCRIPT-MS-HOTFIX.APP.BRN.HAVERHI.PALM.FL.CBH,
    error message: Failed creating SCRIPT-MS-HOTFIX.APP.BRN.HAVERHI.PALM.FL.CBH. With error message: Setting the trustee for BRN.HAVERHI.PALM.FL.CBH on the file "VOL1:\ZEN\UTILS" failed. Look in subscriber log file for more details..
    2008.05.29 03:35:41 [TED:Event Processing] Received (from haverhi-flbrn1.yesbank.com) Creating new application failed,
    Subscriber Tree Name= YOUR-TREE,
    Subscriber DN = SUBSCRIBER_HAVERHI-FLBRN1.BRN.FL.SUBS.SUBSCRIBERS.ZSM.GRS.CBH,
    Golden App = SCRIPT-MS-HOTFIX.APP.BRN.ZENGOLD.GRS.CBH,
    Attempted AppName = SCRIPT-MS-HOTFIX.APP.BRN.HAVERHI.PALM.FL.CBH,
    error message: Failed creating SCRIPT-MS-HOTFIX.APP.BRN.HAVERHI.PALM.FL.CBH. With error message: Setting the trustee for BRN.HAVERHI.PALM.FL.CBH on the file "VOL1:\ZEN\UTILS" failed. Look in subscriber log file for more details..

  • Cannon 8800F not working with OS X yosemite 10.10.1  . I have downloaded the latest drivers and firmware from Canon. I called Canon for support and went through all the checks , but, still my iMac did not see the scanner. Any new ideas?

    cannon 8800F not working with OS X yosemite 10.10.1  . I have downloaded the latest drivers and firmware from Canon. I called Canon for support and went through all the checks , but, still my iMac did not see the scanner. Any new ideas?

    Have you done any of the following?
    http://support.apple.com/kb/PH18614 OS X Yosemite: Reset the printing system
    Repaired permissions & restarted your comp after the installations of the drivers?
    Sometimes, installing the GIMP drivers help with printing issues: http://gimp-print.sourceforge.net/MacOSX.php
    What to do when you can't print
    =============
    not working with OS X yosemite 10.10.1
    Per your profile
    Mac OS X (10.7.3)
    Conflicting info:  Please update/correct your profile so that you can receive the correct troubleshooting suggestions.  This will assist the users in trying to help you.  Thank you.

  • I purchased photoshop CS5 for my windows vista operating system. I purchased a canon 7 D some yrs ago no problem. I purchased canon 7D mk 11 in december 2014. The supplied software will not work with vista. Photoshop CS5 will not accept canon7D mk11. Can

    I purchased Photoshop CS5 for my windows vista operating system. I purchased a canon 7 D some yrs ago no problem. I purchased canon 7D mk 11 in December 2014. The supplied software will not work with vista. Photoshop CS5 will not accept canon7D mk11. Can someone please tell me how i process canon 7D mk11 photos ?????. (is it possible to bypass camera raw and open the photo straight into CS5 without using camera raw first. if so how do i do that. if not how do i process pictures).
    Thank you.
    Brian in the UK.

    Photoshop by itself cannot process raw image data. That is why the Camera Raw plug-in was developed. You could try the DNG converter and convert your images to the DNG format and then the Camera Raw that you have would be able to open them. I can't recommend Lightroom because you are using Vista, and Lightroom 5 cannot be used with that operating system. It may be time for you to get a new computer and upgrade your software.

  • Appleworks does not work with mountain Lion.  What can I use for drawing and painting?

    Appleworks does not work with mountain Lion.  What can I use for drawing and painting?
    MacBook
    Marian

    Please see this article which examines various possible alternatives to AppleWorks:
    http://rfwilmut.net/aw

  • Good Morning, Are there any other donotfollow plug-ins or add ons for the version 4 of Firefox? The one available on your site will not work with version 4. Thank you.

    I am starting to affiliate market and need a donotfollow plug in or add on and the one available on your site will not work with version 4 of Firefox. Is there another place I can go or do you have another add on that will perform the same function as the do not follow you have on your site for the previous versions of Firefox? Any help would be greatly appreciated.

    OK - to answer my own question, Apple recommend 8.2.1, but you can install 9.1.1 and it will run on a G3. Very slowly. Looks like this is the only option. Get it here: http://support.apple.com/kb/DL1036. You need OSX 10.4.11 or later though....

  • Is their a fix for photoshop elements 11 move tool? Not working with Yosemite OS upgrade.

    Is their a fix for photoshop elements 11 move tool? Not working with Yosemite OS upgrade.

    Hi,
    We sincerely apologize for the problem customers are facing while using a trackpad with Photoshop Elements 11 & 12 on Mac OSX 10.10 (Yosemite).
    We have been actively working with Apple to resolve this problem as quickly as possible. We're hopeful this will get completely resolved in an upcoming update of Yosemite(MAC 10.10).
    In the meanwhile, you have two options to work around this problem:
    1. Option1: Use a mouse instead of the trackpad
    2. Option2: Install a plug-in which should workaround the problem
    Plug-in installation instructions:
    1. Close Photoshop Elements
    2. Download this zip file to a location you can easily find (e.g. your desktop)
    3. Unzip the file, WhiteWindowWorkaround.plugin, and move it to the Plug-In folder:
    • For Elements 12 – //Applications/Adobe Photoshop Elements 12/Support Files/Plug-Ins/
    • For Elements 11 - //Applications/Adobe Photoshop Elements 11/Support Files/Plug-Ins/
    You can verify the plug-in is installed by launching the Photoshop Elements Editor and choosing Help > System Info... Scroll to the bottom of the text in the dialog and look for the plug-in name "WhiteWindowWorkaround.plugin".
    Note: This plugin is a temporary workaround and should be used until this issue is addressed in Mac OSX 10.10 (Yosemite). Please remove this plugin once the issue is officially resolved by Apple.
    If you are using a stylus in conjunction with a trackpad, you might see issues with your trackpad. Workaround in this particular case is to use mouse instead of the trackpad.
    Hope this helps!
    Regards,
    vaishali

Maybe you are looking for

  • Safari 4.0.5 OSX & Windows

    I have both Safari 4.0.5 for Windows and Safari 4.0.5 under OSX 10.5.8. I have one site that displays a Flash page peel ad using IE and Safari 4.0.5 for Windows, but the same site does not display the page peel ad using Safari 4.0.5 OSX (although oth

  • Iphone 4s screen is frozen

    help.  My new iphone 4s screen is frozen. 

  • How to set encoding for xml Marshaller?

    Hi, I am using SAPXMLToolkit. And I use XMLMarshaller to convert from xml to java classes (jaxb classes). Now when I get some characters like ü, the marshaller gives an error com.sap.engine.lib.xml.parser.ParserException: Unsupported character: 69(:m

  • Embed a scrolltext in a mc

    I have a flashfile called "start.swf" that loads other swf-files into a mc with the instancename "placeholder" by different buttons. In a file called "mprint.swf". I want a dynamic textfield (with the imprint information) to be loaded into placeholde

  • Oracle ODBC BLOB examples.

    We are currently writing a VB application to harvest data from an Access 2000 database, which is to large to convert to 97 and use migration workbench, and stuff it into an Oracle 8 database, which already has the table structures from the Access dat