Trying to setText on random JPanels via a String array?

My assignment is to create a bunch of JButtons, and randomly have an "X" appear on one, until it is clicked, and then it goes away and reappears on another random one. It does this ten times and displays the time it took to do so.
I've created all the JButtons, named b01 to b48 and put them in a gridLayout. That part works fine.
I created a String[] array with the 48 names of the JButtons in it, then I was thinking I could go this route...
Random r = new Random();
String random = panels[r.nextInt(panels.length)];
random.setText("X");  //This is where the program hangs up.I can replace the setText statement with a System.out.println statement, and it shows up on the console correctly...

Brandon,
Have a chook at my minesweeper game at http://forum.java.sun.com/thread.jspa?forumID=54&threadID=5248903 ... it uses a matrix of cells[rows][cols]... each Cell is a JPanel which contains a Button.
I think you'll end up with something like ...
  // create an array of Buttons
  Button buttons[] = Button[NUM_BUTTONS];
  for (int i=0; i<NUM_BUTTONS; i++) {
    buttons[] = new Button(i);
  // Xify a random button for a random time
  buttons[random.nextInt(NUM_BUTTONS)].xify()I'd create a:
class Button extends JButton
* provides a constructor(int index) which sizes and places the button according to it's index
* provides an "xify" method, which setText("X"), then sets-up a SwingTimer to setText(null) after a random time.
Cheers. Keith.

Similar Messages

  • I get error message "unknown error" When trying to log on to itunes via pc, help please!

    I get error message "unknown error" When trying to log on to itunes via pc, help please!

    Hello, trolle56.
    Thank you for the question.  You may find these articles helpful in troubleshooting the error received with the iTunes Store. 
    Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    iTunes: Advanced iTunes Store troubleshooting
    http://support.apple.com/kb/ts3297
    Cheers,
    Jason H. 

  • HT1175 I am trying to setup my Time capsule via a ethernet cable as a back up for a new iMac. The on button on the time capsule set up window keeps failing to stay on. Any ideas what to do?

    I am trying to setup my Time capsule via a ethernet cable as a back up for a new iMac. The on button on the time capsule set up window keeps failing to stay on. Any ideas what to do?

    A PC can have more issues connecting than a Mac.
    But it really should not matter.. so just try it in situ.. press and hold the reset.. once it starts up, it will return to default IP, 10.0.1.1 the PC should then be able to find it via the airport utility.
    If not drag it over to the Mac and plug in there by ethernet.. or since it is a laptop, really should not be that difficult to drag the Laptop and plug it into the TC.
    Important thing is to get access to the TC.
    The Mac if it is running lion, then you MUST download and install 5.6 airport utility to do anything useful.
    http://support.apple.com/kb/DL1482

  • Error while trying to add a SQL Script via DB02

    Good Morning and happy Sysadmin day to everyone,
    I have the following Problem regarding DB2 9.5
    I'm trying to run a SQL Script via DB02 in an ERP 6.0 System.
    I'm using DB02 -> Jobs -> SQL Script Maintenenace -> Add
    Then there is a Textfield "Script Name". When i'm using the F4-Help I'm getting the following error Message:
    List box value range for field DYN_SED-SCRIPT_NAME could not be created
    Message no. DB6PM004
    Any suggestions what might be the Error?
    Thanks in Advance
    Marco

    Are you trying to create a new Model or trying to import a Model ?

  • Error when trying to Cancel an invoice document via MR8M Transaction

    Greetings Everyone,
    l am having an issue when trying to cancel an invoice document via MR8M transaction. It gives me the following error message;
    SYSTEM ERROR: error in routine MRM_DRSEG_CR_CREATE
    Message no.M8008
    Procedure:
    Contact your system administrator.
    This invoice was related to a check payment. The check has been voided already and there is no clearing document for the accounting document. So, the item remains open. However when l try to reverse, it display the error message above.
    Thanks in advance

    read notes 449277 and 750455, your solution is probably there.

  • HT2305 When I am trying to update my iPad 2 via syncing it with my PC, I get the following error message: "iPad software update server could not be contacted." Any ideas?

    When I am trying to update my iPad 2 via syncing it with my PC, I get the following error message: "iPad software update server could not be contacted." Any ideas?

    Try rebooting your router and or cable modem. Unplug it/them for about 30 seconds and then plug back in. See if it works then. Reboot your iPad as well.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

  • I have just upgraded from an iPhone 3Gs to an iPhone 5. I am trying to transfer all my content via icloud but having problems logging in - it keeps telling me the server is not responding. Nano sim hasn't yet been registered - does this affect things?

    i have just upgraded from an iPhone 3Gs to an iPhone 5. I am trying to transfer all my content via icloud but having problems logging in - it keeps telling me the server is not responding. Nano sim hasn't yet been registered - does this affect things?

    Have you activated your phone with your carrier yet?

  • TS2755 Hi All - I sent a text using my iphone 5 - It is PAYG and had no money in it. It tried to send as an SMS but gave the 'green button reject message'. After deleting the convo, the phone keeps trying to send the deleted text via SMS and wont stop not

    Hi All - I sent an sms using my iphone 5 - It is PAYG and had no money in it. (stupidly)
    It tried to send as an SMS but gave the 'green button reject message'.(no money)
    Step 2 in this stupidity - the phone keeps trying to send the deleted text via SMS and wont stop notifying me of this. Totally ruining the functionallity of my phone, and more so totally annoying. All I want to do is stop the constant re-trying of sending the deleted SMS.
    Any ideas?
    Many Thanks!

    Hi, many thanks for your help - Pressing and holding sleep/reset hasn't worked, the msg is still continually reporting it is failing to send. I can restore to a previous version however I'll lose my paid apps. Is there any way to work around this. I'm only concerned about one app - Epocam HD which I purchased last month. My last backup on PC is 4 March 13 - before I bought the paid app - Itunes advises me I'll have to re-pay to get my apps (app) back. Even though it advises that icloud backed up this morning at 1:30 am (which although it is before the text, I cannot manually select this restore).
    What a mess!

  • I am trying to connect 2 ipod touch via blue tooth. why is it not discovering another ipod via bluetooth?

    I am trying to connect 2 ipod touch via blue tooth. why is it not discovering another ipod via bluetooth?

    ashet8 wrote:
    I wanted to transfer songs.....
    See Here  >  http://support.apple.com/kb/HT1386
    What you can sync
    Applications
    Audio content—music, podcasts, audiobooks, and iTunes U content

  • Trying to create a Chrome app via template

    Hi,
    I am trying to create a Chrome app via the template option in ZAV 11, without any success since only version 35 of Chrome is supported, and only ver 39 is available for download. If I try to create an app via the snapshot third party menu option, the app crashes on start-up, no matter what I do. This is driving me crazy to tell the truth!! Please update the templates to reflect the most current version of Chrome, or remove it completely as this is not a workable option as you now offer it.
    Regards,
    Garth

    I am creating a Virtual app based on chrome and have the same problems. I however did find an older offline installer for chrome. I sent you a PM with a link.

  • I have mac os x 10.6.8. I am trying to back up my information via time machine and it's not letting me click on the "use for back up" option.

    I have mac os x 10.6.8. I am trying to back up my information via time machine and it's not letting me click on the "use for back up" option.

    Using Cloning as a Backup Strategy
    http://www.macupdate.com/app/mac/7032/carbon-copy-cloner
    http://www.bombich.com/software/updates/ccc-3.5.html
    OS X Lion Install to Different Drive
    How to create an OS X Lion installation disc MacFixIt
    Migration Assistant Update for Mac OS X Snow Leopard
    http://www.apple.com/support/lion/installrecovery/
    Create an OS X Lion Install disc
    http://reviews.cnet.com/8301-13727_7-20080989-263/how-to-create-an-os-x-lion-ins tallation-disc
    How to clone your system:
    http://macperformanceguide.com/Mac-HowToClone-backup.html
    http://macperformanceguide.com/Mac-HowToClone.html
    http://www.macupdate.com/app/mac/7032/carbon-copy-cloner
    http://www.macperformanceguide.com/blog/2012/20120711_2-MacPro-internal-clone-ba ckup.html

  • I am trying to activate my iphone 4 via my itunes but i keep getting the error (1) message at the end of restoring.  Any suggestions?

    I am trying to activate my iPhone 4 via iTunes but i keep getting the error (1) message at the end of the restore.  I believe my iphone has to be in DFU mode but i already tried that and same thing.  Does anyone have any suggestions?

    The error is just a simple error message just like (1013) instead it says (1).  The iPhone I am trying to activate has been activated before I just currently have no service and I think that activating it will solve the problem.  I just can't restore through iTunes because it won't finish. I get the message every time I try to restore.

  • HT201210 I have tried to restore my i phone via itunes after doing the update and it keeps giving unknown error occurred (3194) please help

    I have tried to restore my i phone via  itunes after doing the update and it keeps giving unknown error occurred (3194) please help

    Hello Sam-marchesi,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    iTunes: Specific update-and-restore error messages and advanced troubleshooting
    http://support.apple.com/kb/TS3694#error3194
    Unable to contact the iOS software update server gs.apple.com
    Error 1004, 1013, 1638, 3014, 3194: These errors may be the result of the connection to gs.apple.com being redirected or blocked. Follow these steps to resolve these errors:
    Install the latest version of iTunes.
    Check security software and ensure that communication to gs.apple.com is allowed. Follow these stepsfor assistance with security software.
    Check the hosts file. The restore will fail if there is an active entry to redirect gs.apple.com. Follow theadvanced iTunes Store troubleshooting steps to edit the hosts file or revert to a default hosts file. See "Blocked by configuration: (Mac OS X/Windows) > Rebuild network information."
    Try to restore from another known-good computer and network.
    If the errors persist on another computer, the device may need service.
    Best of luck,
    Mario

  • I was trying to make a newspaper purchase via iTunes

    I was trying to make a newspaper purchase via iTunes but I received an error message saying "Your purchase could not be completed. For assistance, contact iTunes support" What should I do?

    Cony1985 wrote:
    I ...For assistance, contact iTunes support" What should I do?
    To Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • I downloaded a rental movie (SD) onto my iPad2 and tried to play on my TV via VGA adaptor; it says not authorised. How come and what can I do?

    I downloaded a rental movie (SD) onto my iPad2 and tried to play on my TV via VGA adaptor; it says not authorised. I have done this many times before. This is the dirst time I have had this  not authorised message. Has anyone any ideas what  what can I do? Many thanks in anticipation.

    Delete the file and re-download again.

Maybe you are looking for

  • How do i move my itunes library from my pc to the icloud?

    i have 3900 songs stored in my itunes library on my laptop.  I recently got an i phone 4S and there isn't enough storage on it to move my songs to the phone.  I purchased 20gb of storage in the iCloud but can't find any instructions to move my librar

  • Dump in webflow RSWNWIEX TSV_ILLEGAL_REFERENCE

    Hello all, We've customized the release of purchase orders workflow. Our workflow has two steps: 1-step one: the responsible receives an e-mail and releases the purchase order. 2-step two: the purchaser receives the decission of the responsible perso

  • ITunes 8.2 not playing any long files

    I've had every single episode of the Ricky Gervais XFM shows from years back on my iTunes for about 3 years now, and have listened to them over and over until I installed this latest version of iTunes. It will now no longer let me play any of the sho

  • BAPI to hold an invoice/document in MIRO

    Hi everyone, I'm facing a problem trying to hold an invoice in MIRO. I'm using the bapi BAPI_INCOMINGINVOICE_PARK, but this bapi creates a parked document, and sets RBKP-RBSTAT as 'A' (Parked), and i've been reading some forums and found that a parke

  • What happened here... Warping? or What

    I just noticed a bending of the aluminum of the screen this morning. I haven't the slightest clue what happened. I have NEVER dropped the machine, keep it in a speck seethru case, which I then put into an incase bag, and then finally put into my back