Best way to delegate events to parent

Hi to all.
I have a problem with a GUI i'm programming. I have the Shop class that extends a JFrame and have several JPanel and other components. Inside one of this JPanel i have an InventoryPanel that extends JPanel and contains JTextfields and a JList.
I've no problems to handle events inside InventoryPanel, but depending on some factors (i.e. the property of objects selected in the JList) sometimes the event must be delegate to the Shop class (so i can disable/enable buttons or set text). Which is the best way to do such a thing?
I thought i could call a method of Shop, but InventoryPanel "doesn't know" how to reference it... should i pass the reference in some way (constructor)?
Or should I conditionally delegate in some way the event to a Shop EventListener? and in this case, how can i do this? I searched through the tutorials and the forum, but it's not too clear to me
Thanks for any help
Wil

The simplest way to implement addListener and removeListener is something like:
public class Foo
  private Vector mFooListeners = new Vector();
  public void addFooListener(IShiftListener listener) {
    mFooListeners.addElement(listener);
  public void removeFooListener(IShiftListener listener) {
    mFooListeners.removeElement(listener);
  protected void fireFooEvent(FooEvent event) {
     for (Enumeration enum = mFooListeners.elements(); enum.hasMoreElements(); ) {
      IFooListener listener = (IFooListener)enum.nextElement();
      listener.fooHappened(event);
  // and somewhere in here you do something that requires a call to fireFooEvent()...
}Note that this code was developed under JDK 1.1.4 so I used Enumeration instead of Iterator. Other than that this is a respectable way to handle listeners.

Similar Messages

  • Best way to remotely control my parents macbook pro?

    Need to install software on my parents macbook, what is the best way?  Can it be done?

    That depends on your skill level. Easiest way is Screen Sharing in iChat. Most efficient is SSH.

  • Best Way to Capture Stored Procedure Calls through Extended Events?

    I am trying implement Real Simple Solution for Database Monitoring:
    If any of the RPC Calls takes more than 200 milliseconds or more than 10K Reads , I want to compile the list on daily basis and sent out an email to our team. We usually did that through RPC Completed event through Profiler.
    We want to Implement the same through Extended Events but SQL Text is not being captured because we are using SQL Server 2008 R2.
    Whats the best way with Extended Events to Capture:
    RPC Calls with Parameters and Values and Reads, Writes, CPU and Query HASH.
    What we currently have is :
    Has anyone done this using SQL Server 2008 R2 and  please let me know.
    IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='LongRunningQueries')
    DROP EVENT SESSION [LongRunningQueries] ON SERVER;
    CREATE EVENT SESSION [LongRunningQueries]
    ON SERVER
    ADD EVENT sqlserver.module_end(
    ACTION (sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_id, sqlserver.plan_handle, sqlserver.session_id, sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.username)),
    ADD EVENT sqlserver.rpc_completed(
    ACTION (sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_id, sqlserver.session_id, sqlserver.sql_text, sqlserver.username)),
    ADD EVENT sqlserver.sp_statement_completed(
    ACTION (sqlserver.client_app_name, sqlserver.session_id))
    ADD TARGET package0.asynchronous_file_target(
    SET filename='G:\LongRunningQueries.xet', metadatafile='G:\LongRunningQueries.xem')
    WITH (MAX_MEMORY = 4096KB, EVENT_RETENTION_MODE = ALLOW_MULTIPLE_EVENT_LOSS, MAX_DISPATCH_LATENCY = 300 SECONDS, MAX_EVENT_SIZE = 0KB, MEMORY_PARTITION_MODE = NONE, TRACK_CAUSALITY = ON, STARTUP_STATE = ON)
    ALTER EVENT SESSION [LongRunningQueries] ON SERVER STATE = START
    I90Runner

    Hello,
    Please read the following resource.
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d6d51f6e-c01b-4880-abb2-4f0cfd1f4531/extended-event-trace-on-event-rpccompleted-not-capturing-sqltext-action-unable-to-retrieve-sql?forum=sqldatabaseengine
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • What is the Best way to Move FCPX files to External HD?

    Im running low on space on the HD,  What is the best way to move events, videos, etc.. to an external HD from FCP X and still have FCPX locate and use them?

    Thanks Tom,
    In the finder in Movies I have motion templates, final cut events, final cut projects.  Is that what you mean by project library?
    The FCPX project library doesnt really have anything in it.
    Thanks!

  • Best way to read tracks of a MIDI file

    What is the best way to read events (sequentially based on time) of the tracks in a midi file ? Should they be read serially (track 0 all the way through then track 1, etc) or parallel based on some measure of time (of all tracks)?
    Edited by: yz2zy on Jul 24, 2009 11:18 PM

    Depends on what you're doing to it, I suppose.

  • I want to back up2 hard drives with imovie events and projects as well as 2 desktops. Is TC the best way to do that

    I want to back up 2 hard drives with imovie events and projects as well as 2 desktops. Is TC the best way to do that? Also, I already have a wireless network. Does this create a 2nd one or is it possible to just use it for the backup function?

    Time Machine can do that, if your Time Capsule is large enough (see #1 in Time Machine - Frequently Asked Questions).
    For backing-up multple HDs on a single Mac, see #32 in that same link.
    If by "2 desktops" you mean 2 separate user accounts on the same Mac, see #26 there.   If you mean 2 Macs, see #33.
    You might also want to review the Time Machine Tutorial.

  • Best way to handle an event from WaitForSingleObject

    Hello LV experts,
    I would like to know what's the best way to handle an event which I catch using the Win32 API (WaitForSingleObject) in Labview(7.1 or 8.20).
    I know there is too many possibilities to do this, but I want to do it  on the best way. that is why I would like to have ideas and tips from you.
    Any and all tips appreciated

    You can download the Library from this link. Inside is an example that shows how to handle windows messages/events.
    http://zone.ni.com/devzone/cda/epd/p/id/4394

  • Event Structures​-best way to implement this UI?

    I am trying to write a VI to control & read data from 4 different "channels" (each measuring a DUT) at once.  I have written all the VI's for initializing instruments, communicating with the devices (VISA, GPIB), setting bias, reading data, etc...that has all completed. I just need to write the overall program with the user interface to allow the user to control these 4 channels & display the measured data.....as it turns out, this is the tricky part! My head is spinning from trying to figure out how to handle all the possible events.
    Basically for each channel, I want the user to be able to
    -enable/disable it  for measurement (e.g. if  there is no device loaded in Ch.3, we don't want to measure Ch.3..maybe disable/grey everything)
    -set bias conditions (only if channel enabled). Allow user to change bias "in real-time" by increment/decrementing (e.g. incrementing from 5.00 V to 5.01 V, for example).
    -turn biasing on/off (again, only if channel is enabled)
    Also,  I want each channel to display its measured data (e.g current, temperature reading)..every second or so. No graphs or anything fancy (for now! ), just numeric indicator. 
    Honestly, this all sounds so simple but I'm having trouble figuring out the best way to implement this, due to the fact that 1) there are multiple channels needing to be monitored for events  2) large number of user events that could occur (seems like at least 4 per channel - enabling/disabling, turning bias on/off, incrementing/decrementing bias values, etc ), Also the if a channel IS enabled, i want to be continously reading/displaying the data.  What is the best way to handle this? Should i have 4 separate while loops, each with an event structure to handle events for that particular channel..or will that give me grief somewhre? 
    Also, I have another nagging question. Pretty much all the examples I see re: Event Structures and booleans involve latched booleans, eg. buttons that are just pressed once and pop back up...e.g. buttons you press to tell it to complete a task (e.g. "Acquire Data" or "Stop") , and once it's pressed it's over and reset.  In my case, some of the booleans would not be latched...e.g. the "Enable Ch.2" button would be 'TRUE" as long as i want Ch. 2 to be read....does that make sense? Then, say hours later,  if i did want to disable that channel,  i would change it to "FALSE" and while that would be an "value change", the new value would not be "TRUE"..does that make sense? So  not sure if that would be dealt with the same way in an Event Structure. 
    Hope this all makes sense and many thanks in advance for any help!!!

    You're halfway there. I'd say the best solution is a producer/consumer structure, the event structure is used to generate queued commands to the consumer loop.
    All data is handled in the consumer loop, where you among other things have an array of clusters of channel/instrument settings. (I usually have several cluster, one for test data, one for instrument settings, one for general settings and so on)
    The event structure can have a 1 sec timeout, in which you queue up a Measure command.
    In the consumer, in the measure state you loop through your instruments and if enabled you measure them and update their indicators.
    The general (smart) way to setup the queue is with a cluster containing 2 elements, a typedef'd Command and a variant.
    This way you can send data with the command in any form which is then interpreted in the consumer.
    If, e.g. you press the Enable button on a channel, you can enqueue Enable and the channel number.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • Best way to create DVD from videos from several events?

    Hi all - I'm very new to iMovie and iDVD and was hoping for some advice. I'm making a compilation DVD "for the grandparents" of videos from a variety of the kids' events throughout the year. What's the best way to do this? By the way, I've switched to using iMovie HD but am still using iDVD '08. I've been prototyping a few things and came up with the following options:
    Option 1: Create one iMovie HD project and import all the videos from the various events into one timeline. I then create the chapter markers as usual, then Share with iDVD.
    Question: I want each of the event videos to return to the DVD Menu. How would I do that if all the videos have been combined into one timeline in iMovie HD?
    Option 2: Create each event video under its own iMovie HD project. Export each video into .dv format (I don't know what the best format would be). In iDVD, insert each video.
    Questions: Would I lose video quality going this route? If I wanted to create chapter markers within each event video, I assume I would lose them once I've exported to .dv format?
    Which of the above would be a better option? Is there a better option?
    Thanks!

    If you make changes to your iMovie project, the next time you open your iDVD project a pop-up will inform you that assets have been updated and asks if you want to update. Click update and your changes will be incorporated. As long as you haven't changed locations of your iDVD project and iMovie project, iDVD will point to the ongoing iMovie project. But if you move your iDVD project to another drive, or rename the iMovie project, iDVD will tell you that there are missing assets because it can't find your iMovie project. At least, that's what happens to me when I do that.
    Happy Turkey day!

  • Best way to deal with same members having different parents/children

    We have a situation where some nodes need to have different parents for different application but they exist in the main hierarchy. What is the best way to deal with it? The nodes used are pretty much the same.
    Is it best to create a new hierarchy within the same version and let the nodes have different parents in it?
    -- A

    Every node has a parent in the hierarchy. You said that some nodes need different parents for different applications.
    Do these 'different parents' exist further up the tree? If they do then you can create a boolean input property that flags the nodes that exist JUST for the application. Create a new property (call it NewAppParent, let's say) with a formula that recursively climbs up the tree to find its next parent for the application, and export NewAppParent as the parent value.
    If the parent does not exist in the hierarchy then you should create an alternate hierarchy.
    If the parent exists in the hierarchy and is not an ancestor of the node then you're out of luck. Unless you create an alternate hierarchy with unique parent names.
    D

  • Best way to query extended events file in sql server 2012

    Hello all,
    is there any best way to xquery extended events async file i am having hard time sorting  out data in GUI and using xquery.
    Any help highly appreciated.
    thanks,
    ashwin.

    Yes, there might be better way to write it the way you did it. But since I don't know what you wrote or what you are looking for I can't give any advice. You need to be more specific.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Best way to archive HD movie (Raw, events, projects, etc.)

    Hi everybody,
    I've been using iMovie for the last 12 months, to make small family movies (shared on internet and via DVDs).
    I am having more and more footage and the question comes about the archiving of all this.
    What's the best way to keep all important files ? (keeping the quality, and saving space if possible)
    How do you proceed ?
    I have the different ideas, found on internet, but not sure what is the best.
    I can directly make disk image from the camera memory cards. If at later stage I need to import again, I can do it from that mounted image. And this is keeping the original quality. (I think.. right?)
    After finishing a project, do you still keep the imported files ? (the events, I think it's called).
    And, do you also keep the final version of the project, accessible in iMovie ?
    I usually send the movie on internet, and burn on DVDs. Is there a need to keep this project, in my archives ?
    I am very curious to learn how the advanced users, with tones of footage, are doing to archive their precious movies.
    Thanks a lot for your help and information.
    Thierry.

    Hi Thierry,
    I am using AVCHD, on MSDuo. Until now, I was doing disk image, from the Apple disk utility. I saw the back up feature in iMovie, but never tried it.
    Is it doing the same ? You prefer to use the integrated back up from iMovie ?
    Yes, the built-in archive feature in iMovie works much the same as the disk image method you have been using. iMovie can't use the .MTS files on their own, so the archive replicates the camera contents, including the full directory structure. Full quality is preserved, just as recorded by the camera. The only downside is that each time an archive is performed, iMovie archives the full camera contents, irrespective of the fact that some content may have been archived previously. In other words, you can't selectively archive individual clips - it's all or nothing. So, if you do an archive then record further footage without deleting the previous content from the camera (or card), the full content (including the earlier clips) is archived when next performed.
    To get around this limitation, I use RevolverHD from Shedworx - found here: http://www.shedworx.com/revolverhdmac (this allows selective archiving from the camera, but there are issues with retaining the timecode when importing from the archive to an Event).
    John, you are using external drive for the Events and Projects, meaning that you are working directly from external drive? (or you were refering to the storage, after you are done on the mac?)
    I'm working directly from the external FireWire 800 drive for the Events. My Projects are all on the MacBook Pro's internal drive. My understanding is that iMovie works more efficiently with this set-up. My archives are also on the same external drive as the Events - this is probably not a good idea, but I do back-up the drive frequently, and also copy the archives to a portable drive as added security.
    Note that my exported Projects are stored by default in the Projects package contents folder on the internal drive (I use Share>Media Browser). But I also copy these exports to a separate portable drive which I connect to a Western Digital Media Player for playing through my widescreen LCD TV. I also produce DVDs from the exported files (but only as required).
    And what about the final versions of your movies ? (the one in the media browser, or on the DVD that you burnt) Are you also archiving the final products ? (it's not too heavy to keep all ?)
    As I mentioned above, by default iMovie places the shared movies (via Share>Media Browser) in the Project folder (on my internal drive). To access the shared movie, go to your User/Movies/iMovie Projects folder and right-click (or Control-click) on the Project name. From the pop-up menu select "Show Package Contents". Click on the Movies folder and you will see the shared movie, labelled (for example) as 720p.mov or medium.m4v and so forth. The main reason for copying this shared move to a portable drive is to view it through my Media Player. I just unplug the drive from my Mac and plug into the Media Player. I don't need it as a back-up as I'm running Time Machine - this backs up my internal drive, so all my original Projects and exports are covered by Time Machine.
    Hope all this makes sense Thierry. I'm probably keeping too much, but have plenty of storage capacity so prefer not to get rid of anything at present. Things may change as storage runs down, of course! I may need to do some housekeeping then.
    John

  • What is the best way to save iMovie Events?

    I would like to save iMovie Events for future use but the files are so big that I need to have several external hard drive. What is the best way to save these files? Burn to DVD discs?

    mihomle wrote:
    .. but the files are so big that I need to have several external hard drive. .. Burn to DVD discs?
    1 TB of harddrive space actually <60€ .. drag'n drop files, done. instant access for future projects.
    1 TB of DVD disk space (4.4GB x 230 pieces, each ~50¢) = ~115€ + hours of work .. hours of re-importing in future use ...
    => I prefer ext. HDD.. 1TB fits ~ 75h miniDV, or 40-60h HiDef imported (using the 'Archive' feature of iM09 much more) ..

  • Although we have iPhones and iPads, this is our first mac pc and we wanted to know the best way to set up multiple users with parental contro;s

    although we have iphones and ipads, this is our first imac and we wanted to know the best ways to set up multiple users with parental controls

    I'm assuming you have the lastet OSX version 10.9 "Mavericks." Here are some useful links from Apple I think will help:
    http://support.apple.com/kb/PH14414
    http://support.apple.com/kb/PH14099
    http://support.apple.com/kb/PH14280
    and a video:
    http://support.apple.com/kb/VI28
    I suspect you have a newer iMac than the pre-2006 models this forum covers (the forum labels are unbelieveably vague). If you can confirm that yours is newer than 2005, I can ask the Hosts to move you the the forum for current iMacs, which gets many more views.

  • TS1314 I have lots of organized photos on my PC and I want to keep them organized to sync to ipad.... how is the best way to do this?

    I have spent a lot of time saving, organizing and arranging photos (for the last 7 years) on my PC, and would like to know the best way to transfer these, AND MAINTAIN THE ORGANIZATION OF THE FOLDERS, to my new ipad (and later, my iphone). I have a really good system, and I do not want to have to do it all over again, on the ipad. I DO NOT want to subscribe to another monthly service fee (i.e. the iCloud) but DO have iTunes on my PC.
    What is the simplest method to do this ?  I have tried synching, but, each time have lost photos (on my ipad) OR have had NO ORGANIZATION AT ALL to the photos once synced.  I have all these photos (5.6gb) in the My Pictures folder, then subdivided into years, then subdivided into events and months within the years.  So, my transfer of the My Picures folder, completely transfers all of them, but with NO further organization.  Again, I have spent years doing this, and don't want to have to re-invent the wheel. 
    Can someone advise (or even better, lead me to a youtube video) that accurately shows the best way to do this ?
    Thank you, in advance, for your help.
    p.s.  I particularly enjoy Dan Nations very informative articles on how to get the best from my products.  And, wish Apple would explain "how it works" regarding the syncing methods on the Operating System.  It is the only thing I "don't get" about using my iPad..... meanwhile I LOVE my new mini ! ! ! ! ! ! ! thanks Apple, for keeping things simple.... Please don't change that !

    Correct, it will only be one-level, the Photos app doesn't support sub-albums - the sub-folders photos will be included in the parent's album.
    If you select My Pictures at the top of the Photos tab when syncing, then you should get an album for each folder that is directly under it - so if I understand correctly what you described then that would mean an album for 2013, one for 2012 etc. And each of those should include all the photos in the subfolders under it - so 2013 would include the photos from the events and months subfolders under it.
    You can't sync them separately, only the contents of the last sync remains on the iPad, by not including a folder in the next photo sync you are effectively telling iTunes that you no longer want that folder/album on the iPad so it will be removed and be replaced by the contents of the new sync (you can't delete synced photos directly on the iPad, instead they are deleted by not including them in the next sync).
    The app that I use, Photo Manager Pro, allows you to select and copy a folder (via FTP), but you would need to select each subfolder individually, which if you have a lot would be time-consuming (I think that if you select '2013' it would ignore the folders beneath it).

Maybe you are looking for