ActionCommand and getSource() are not enough

Hi,
I have a question about the basic concept of event-handling in Java. I'll illustrate my problem by example.
Suppose my program contains two classes, i.e Main and GUI, whereas MainClass implements ActionListener. The action takes place on a JPanel in GUI with a JButton (for invokation of a JColorChooser) and a JComboBox (listing the index of an object which color can be changed) on it. What I want to do is the following: Click on the ColorButton, choose a color and apply it to the object with index specified by the JComboBox. This should be done in MainClass. Normally the ColorButton has an ActionCommand, i.e. "Color changed", but this information is not enough, I have to know which object is meant. So what is the right way to handle events if additional information is needed like in this case the object index? Maybe one has to pass some data through the ActionEvent.
I hope anybody can help me.
Thanks in advance.
Manticore

Here are two alternative approaches. There are several more.
1.
A JComboBox will fire ActionEvents when its selection changes. Since your MainClass is already implementing the ActionListener interface, you can let it listen to these changes just as it listens to events from the button. If the source of the ActionEvent is the JComboBox you get its selected item and store it, so that when the event from the button comes you know which item is selected.
2.
Have a method in your GUI class that retrieves the currently selected item from the combobox. The MainClass then needs a reference to the GUI class, and it can call that method when the ActionEvent from the button occurs.

Similar Messages

  • SSRS 2008 Column Chart with Calculated Series (moving average) "formula error - there are not enough data points for the period" error

    I have a simple column chart grouping on 1 value on the category axis.  For simplicity's sake, we are plotting $ amounts grouping by Month on the category axis.  I right click on the data series and choose "Add calculated series...".  I choose moving average.  I want to move the average over at least 2 periods.
    When I run the report, I get the error "Formula error - there are not enough data points for the period".  The way the report is, I never have a guaranteed number of categories (there could be one or there could be 5).  When there is 2 or more, the chart renders fine, however, when there is only 1 value, instead of suppressing the moving average line, I get that error and the chart shows nothing.
    I don't think this is entirely acceptable for our end users.  At a minimum, I would think the moving average line would be suppressed instead of hiding the entire chart.  Does anyone know of any workarounds or do I have to enter another ms. connect bug/design consideration.
    Thank you,
    Dan

    I was having the same error while trying to plot a moving average across 7 days. The work around I found was rather simple.
    If you right click your report in the solution explorer and select "View Code" it will give you the underlying XML of the report. Find the entry for the value of your calculated series and enter a formula to dynamically create your periods.
    <ChartFormulaParameter Name="Period">
                      <Value>=IIf(Count(Fields!Calls.Value) >= 7 ,7, (Count(Fields!Calls.Value)))</Value>
    </ChartFormulaParameter>
    What I'm doing here is getting the row count of records returned in the chart. If the returned rows are greater than or equal to 7 (The amount of days I want the average) it will set the points to 7. If not, it will set the number to the amount of returned rows. So far this has worked great. I'm probably going to add more code to handle no records returned although in my case that shouldn't happen but, you never know.
    A side note:
    If you open the calculated series properties in the designer, you will notice the number of periods is set to "0". If you change this it will overwrite your custom formula in the XML.

  • Aperture ate my picture files and they are not recoverable.  The guy at the Genius Bar told me to Trash the App, empty Trash, then go to Purchases and reinstall.  But Purchases says it is "Installed" so it does not let me download it again.  HELP!!!!

    Aperture ate my picture files and they are not recoverable.  The guy at the Genius Bar told me to Trash the App, empty Trash, then go to Purchases and reinstall.  But Purchases says it is "Installed" so it does not let me download it again.  HELP!!!!

    I typed Aperture into Spotlight and sure enough it did show up.
    It looks like it is supposed to be in Apps.
    But it is not there.
    So I clicked on the spotlight Aperture and it opened up the App!!!!
    But I do not know where it is to move it!
    How can I find it?
    While Aperture is running and you are seeing it in the Dock, ctrl-click (or right click) the Dock icon.
    You will see a contextual menu. Click on "Options", then select "Show in Finder".
    And check the "keep in Dock" mark, so you will not lose it from the Dock.

  • Colormunkie Photo printer profile (*.ICM and *.ICC ) are not seen by LR4.2 in the Print Job section

    Colormunkie Photo printer profile (*.ICM and *.ICC ) are not seen by LR4.2 in the Print Job section
    I used Colormunkie Photo to create an .ICM file for printer calibration.   When that failed I tried changing the suffix to .ICC.  Under neither circumstance did LR4.2 display the file in the menu to select printer profile.  There were several display files with both suffixes but no printer files at all.  I tried three times with no success and cannot think of what else to try. The first two were the same.  I varied the file creation name suffix in the third.  Help will be appreciated. My OS is Win 7 ultimate SP1  Printer is HP 2550L laserjet.

    Tillman
    Glad you found your answer, Colormunki is smart enough to figure out the color space for the printer as I found out - But for quality work the latest generation of inkjet printers from Epson and Canon are hard to beat, and compared to a laserjet the quality is like night and day. The other benefit of changing up to an inkjet printer is the choice of papers available which you could not put through a laserjet.
    I had a colleague that tried printing on Photoglossy paper through his color laser and it fried the fuser, and HP, while they replaced the fuser unit under warranty, made it very clear that that was a daft thing to do.
    So if I were in your position I would go with an inkjet and you will then enjoy the benefits of better quality output, better paper choices and with your Colormunki be able to make custom profiles that will work in LR
    Cheers
    Mike

  • All my songs and pictures are not transferring from my old phone !!!!!!

    I had the iphone 4S and yesterday I went and got the iphone 5. I am trying to transfer everything using my icloud. All my apps,notes,txt msgs,contacts... everything like that was added onto my new phone. My pictures & music however, are still all adding, it has been loading since last night, this morning I noticed that it has stopped loading on this one song, and this one picture ( I have ALOT of pictures & music) so when I go into my photo app is says " downloading 2,027 of 2,984 " and it hasnt changed for hours!!! Same with my music I go into itunes and it says I have 26 songs left to download and they are not loading, they all say " waiting..." below them!!!
    What should I do ? ..or will it EVENTUALLY load. I must have enough space on this new phone because I did on my old one....and I have deleted quite a few apps that were added from my old phone to my new one.
    Pleasssseeeeeee HELP, thankkkssss (:

    Check what steps you have taken against this
    http://support.apple.com/kb/ht2109
    After that time I suspect it has "frozen "
    Start again having checked out above

  • Keyboard and trackpad are not working, Keyboard and trackpad are not working

    I'm using MBP 15" late 2008 with Maverick OS. A couple of days ago, the internal keyboard and trackpad are not working at all. I did all the troubleshooting. I even reformat it; installing the snow leopard and re-installing the maverick but no good result. I believe there's no problem with my keyboard because i can still do PRAM on my lappy. Everytime i'm booting up my MBP, it always looking for bluetooth trackpad and keyboard. I have not used those bluetooth peripherals from day 1 i've started using MBP. I just read on the internet about the same problem has happened on MBP 13" retina and APPLE fixed it by updating the software. I wish Apple will also do something for the old MBP to fix the intermal keyboard and trackpad problem.

    Reset SMC.     http://support.apple.com/kb/HT3964
    Choose the method for:
    "Resetting SMC on portables with a battery you should not remove on your own".

  • I have spent probably a few hundred dollars on movies, music and apps on itunes. I have only ever downloaded this on my iPhone. I plugged my iphone into a laptop and now all my music and videos are not showing up on available downloads. WHAT DO I DO?!

    All of my music is gone. I have no idea how to get it back and Im worried because it isnt showing up on available downloads.

    Isn't iTunes 10.5 r 9 a beta release for developers?  If that's the case then isn't there a special web site for developers to discuss issues (and they are not supposed to discuss them on the public forum)?  If you're not a developer and have this through unofficial channels then I'm not sure you can expect full functionality.

  • Please help! I defragged my hard drive and now Illustrator CS6 is trying to open all of my complex Illustrator files with a "Text Import Options" box as if they are text files, and they are not opening!

    Please help! Illustrator CS6 started trying to open all of my complex.ai files with a "Text Import Options" box as if they were text files, and they are not opening!  Help!

    Hi Monika,
    I have spent the last two or three days trying to do what you suggested.  I uninstalled Adobe 6 from Windows.  Some files that CS6 placed on my system during installation remained, including fonts and .dll files.
    I had to abandon the Cleaner Tool you suggested because in one screen it allowed me to specify removing CS6 only, but on the following screen it only gave on option to remove ALL Adobe programs.  I could not do that because I didn't have the serial number handy for CS3 in case I want to reinstall it at some point.
    I tried to get technical help with the Cleaner Tool problem but no definitive help was available, so I reinstalled CS6 again without having the benefit of the Cleaner Tool.  I tried to get the serial number for CS3 so I could use the Cleaner Tool but spent 2 wasted hours in chat.  Even though I had a customer number, order number, order date, place of purchase, the email address used AND 16 digits of the serial number, in two hours the agent couldn't give me the serial number.  After two hours I had nothing but instructions to wait another 20 minutes for a case number.
    Illustrator CS6 is still trying to open some backups as Text and otherNone of the problems have been fixed.  I have tried to open/use the .ai files in CS6 installed on another system and am getting the same result, so I don't think the software was damaged by the cleaner.  The hard drive cleaner is well-known and I've run it many times without any problem to previous versions of Illustrator or any other programs.
    When I ordered, the sale rep promised good technical support and gave me an 800 number, but after I paid the $2000, I learned that the 800 number she gave me doesn't support CS6 and hangs up on me.  Adobe doesn't call it a current product even though they just sold it to me about 3 weeks ago.
    Would appreciate any help you experts can offer.  If I can't solve this, the last backup I can use was from June and I will have lost HUNDREDS of hours of work and assets that I cannot replace.
    Exhausted and still desperately in need of help...

  • I am new to iMovies.  When I make a video using the mic and camera in my Macbook Pro, the audio and video are not in synch.  Very annoying.  How can I fix this?

    I am new to iMovies.  When I make a video using the mic and camera in my Macbook Pro, the audio and video are not in synch.  Very annoying.  How can I fix this?

    DVD drives read the bottom of the disk, not the top. Smooth out the paper & try again.

  • On my macbook pro I have a message on my homepage telling me that certain items want to use my keychain. I've pressed cancel the message will not go. The mac is now running very slow and iphoto and safari are not working. Can anyone help?

    On my macbook pro I have a message on my homepage telling me that certain items want to use my keychain. I've pressed cancel the message will not go. The mac is now running very slow and iphoto and safari are not working. Can anyone help?

    What version of Mac OS X?
    What home page?
    What browser?

  • TS4425 when trying to access photo stream on Apple TV, I am getting the error message terms and conditions have changed, but when I go into iCloud on my Mac the new terms and conditions are not appearing - How can I manually agree to them ?

    When trying to access photo stream on Apple TV, I am getting the error message terms and conditions have changed, but when I go into iCloud on my Mac the new terms and conditions are not appearing - How can I manually agree to them ?

    Welcome to the Apple Community.
    The following article(s) may help you.
    Photo Stream ToU's

  • I receive an error stating user name and password are not valid on my ipad and iphone 3Gs when attempting to load email from my icloud account. When I log onto icloud from my Mac, it wont load the email either.

    One day, my ipad and iphone pick up my emails (.mac account) from icloud just fine. the next day, I recieved error messages that say my user name and password are not accurate. I removed the icloud program on both devices and added it back on to both devices and get the same message. I logged into icloud from my Mac and while I can log in, it times out when I select email and wont load the email there either. Any Suggestons?

    I am having the same problem; it started about 24-36 hours ago.
    I know my ID/PW combo are correct because I can access all other aspects of iCloud except mail.
    iPhone -- returns incorrect ID / Password
    iPad -- Same
    Mail.app on Mac -- returns incorrect password error
    icloud.com -- allows me to log in and use all functions accept mail.  When I try to use mail it stays on a white screen for about 60 seconds then returns a dialogue box that indicates a server error.
    I contacted Apple and they placed my iCloud account into something called "Troubleshooting" mode.  They generated a new strong password and sent it on to "Engineering."
    I suspect there are a small number ofo users like you who are affected with the same problem I am.  Too small a number for it to be reported as an outtage.  I suggest you call Apple and open a case to have your mail investigaged.
    Hope this helps...

  • TS3048 turned off my desktop mac, now both my mouse and keyboard are not connected. i am not logged in yet as well, dont know what to do ?

    turned off my desktop mac, now both my mouse and keyboard are not connected. i am not logged in yet as well, dont know what to do ?

    Try resetting the SMC (no peripherals required).
    Barry

  • HT4314 I have two ipods in my house that were set up under the same email.  I have since assigned two different emails.  How can I change the game center account so that is not shared by both ipods because it is for two different users and they are not ha

    I have two ipods in my house that were set up under the same email.  I have since assigned two different emails.  How can I change the game center account so that is not shared by both ipods because it is for two different users and they are not happy?

    By "game center account", do you mean Apple ID?
    If so, you can change it.
    1. Tap settings and navigate to iTunes and App Stores
    2. Tap "Apple ID" and then tap "Sign Out"
    3. Log in with a different ID.

  • Ive just upgraded my late 2009 macbook, and things are not working properly. First of all, when I started the computer first time after installing Mountain Lion, some message advised me that some files were impossible to install.

    Ive just upgraded my late 2009 macbook, and things are not working properly. First of all, when I started the computer first time after installing Mountain Lion, some message advised me that some files were impossible to install. Once I wrote my password, and for now on, everytime I start the session, another window advise me that "Java SE 6" is missing, due that, the computer can't run some "CS5Service Manager". If I try to install it, the download ends with an error. If finally, you skip the istallation, you arrive to the dock, but the menu bar at the top of the screen doesn't show up.
    In addition, my trackpad doesn't works either. I can move the arrow but i can't click anywhere, probably because the option of clicking by touching is disabeled and I can't performance a regular click.
    I'll be very glad if someone know what the heck is happening with my computer. Anyway, I'm going to the genius bar next Saturday. Thx!

    We're sorry.
    We can't find the article you're looking for.
    Please return to the Apple Support homepage.
    Sigh.

Maybe you are looking for

  • DOCMAS Error while checking in and storing

    HI Gurus, i need to send Documents from one system to an other System. I use BDA5 Both system are using different File Systems and the DMS Archive is also different. I can send the DOCMAS without errors. When i Try to process the Documents i can not

  • Error Message when trying to view/edit clips from Flip Cam

    I am trying to edit some video from a flip cam on Final Cut Express 3.5.1 and it won't play. I've imported it both from an external HD and also the laptop itself and both times I get 2 error messages. First "General Error" then "Error: Out Of Memory"

  • Unable to clear Keywords metadata value

    Hello, I'm trying to clear the keywords metadata field using the following code but it doesn't work as expected. No errors just doesn't clear the Keywords field. var xml = new XML(doc.metadata); var nsrdf = new Namespace("http://www.w3.org/1999/02/22

  • Merge Cells Without a Break?

    Post Author: JT21598 CA Forum: Desktop Intelligence Reporting All, Basically what I am trying to do is merge some cells that have duplicate values in them.  The records themselves are not duplicates but there are certain values within those records t

  • Can I share internet with my powerbook g3 using iphone over usb

    Is it possible to connect an old powerbook G3 (running OS10.4.11) to the internet using in iPhone over USB? The USB port currently does not show up as an option in the network preferences.