Is there a way to "throw" the event handling task

I want to create a ButtonPanel class (extends JPanel), and this ButtonPanel class will add 3 buttons to it (in a GridLayout). But I don't want this ButtonPanel to control the event handling for these buttons, I want the JFrame or whatever container above the ButtonPanel to be controlling the ActionListener for the buttons. If I do this
button1.addActionListener(this)is there a way for me make the ButtonPanel pass the ActionPerformed() task to the container above it?
or better yet what should the "?" be in this statement?
button1.addActionListener(?)so that the ActionListener (the one doing the actionPerformed) will always be the container containing the ButtonPanel. Thanks...Happy Thanksgiving.

Well.. I can't be sure this is "good design", but this is how I usually do it, and it works well for me, for a few reasons.
1. The ButtonPanel is accepting an ActionListener (an abstract interface) instead of a contrete class such as a JFrame or the actual class. This move allows the Panel to be re-used in similar situations as long as there is something to handle the button's events.
2. The JFrame is the best candidate to handle the event since it holds the other components that this button click is suppose to manipulate. Of course if there are other components more suitable, I would make it implement the ActionListener instead of the JFrame itself.
Of course there are many other ways to do this, such as using an anonymous inner class, but that won't work in your case since you want the parent Frame to handle the event. I would like to learn about other good methods of achieving this as well!

Similar Messages

  • Is there a way to detect the event when device goes to sleep and the screen blackens?

    I want to detect the event when the iOS device goes to sleep and the screen blackens?
    Is there any way to do it?

    Hi,
    A small idea, please check whether it will work or not.
    You can achieve this by using combination of DNS server and reverse proxy server.( Customized apache). Make 'A' record for www.abcd.com to reverse proxy server IP address in your DNS.
    So it will resolve your reverse proxy IP address for requests.
    Configure appche to accept incoming request for www.abcd.com and points towards www.abcd.com/parameters.
    I think this will solve your problem.  Only one condition is that proxy server will communicate with www.abcd.com on behalf of client.
    Follow the link for configuration of reverse proxy server
    http://www.slashroot.in/how-configure-basic-apache-reverse-proxy
    HTH
    Naisam

  • Is there a way to disable the "user forward task" from workspace in ES2.

    In ES2 "Assign Task" operation there is no taskACL options to uncheck the "Forward" option to disable the user from forwarding their tasks. I think this option is available in workspace start point, but my process is not invoked/triggered by workspace start point. So can any one help me with this?

    At the top of the properties tab there is a toggle for basic/all.  Switch to all and the "Task Access Control List (ACL)" will be available like the deprecated assign task.

  • Officejet 6600 is there a way to attach the document handler?

    How do I re-attach the document handler ono this HP OfficeJet 6600?

    Hello corgi3girl,
    Welcome to the HP Forums.
    When you say Document Handler, do you mean the Automatic Document Feeder (ADF)?
    Are you able to take a picture and send it as an attachment on this file so I can see what it is we are exactly dealing with?
    I will be more than happy to help so please write me back when you have time.
    Cheers, 
    Click the “Kudos Thumbs Up" at the bottom of this post to say “Thanks” for helping!
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    W a t e r b o y 71
    I work on behalf of HP

  • Is there a way to download the events and details on the calendar?

    Can I  download /synch Calendar events and details to my computer?

    Curious, that will synch the calendar?
    I actually sat here and realized my calendar is synched to a personal calendar I keep in gmail. No, duh Techie Betty... Thank you!

  • Is there a way to make an event handler to watch for inbound socket action?

    So I have a program that I've put on hold till spring break: Its a simple TCP/IP chat program for MUDs or IRC servers. Now its time to get this monkey running.
    Right now I have a problem where it locks up after initiating the connection to release after the server disconnects on it's side. I've tried futzing with threads but that was too complicated for this problem. If I could just have it act like an event where it spits out the info received from the IRC/MUD server, that would be ideal.
    Any suggestions?
    PS: In the past I tried posting my code but no one here seemed to understand what I was trying to do.
    CodeDragon

    There's nothing built-in to do what you want. I looked at the code from your old posting and I see two potential problems with yoru read code.
    1. I'm not sure why are you using the "in.reset()"... I doubt that's the cause, but I don't think you need it.
    2. I think your loop is incorrect. Your loop will keep reading until the Reader hits the EOF--which is a server disconnect in this case.
    What you want is something like:
    boolean eof = false;
    while(in.ready() && !eof) {
       String line = in.readLine();
       if(line!=null) {
          scroll.append(line);
          scroll.append('\n');
       } else {
          eof = true;
    }If you wanted to make this asynchronous, use your old loop, but push the lines out to a queue of some sort...somethign like:
    java.util.BlockingQueue <String>queue = new BlockingQueue<String>();
    Runnable r = new Runnable() {
    public void run() {
       String line = null;
       while( (line = in.readLine()) != null) {
         queue.put(line);
       queue.put(null); //tells your loop to abort
    Thread t = new Thread(r);
    t.start();
    String line = null;
    while( (line = queue.take()) !=null) {
       System.out.println(line);
    }Edited by: James_Schek on Mar 20, 2008 4:50 PM

  • Is there a way to put the same event on multiple icloud calendars?

    Is there a way to put the same calendar entry on multiple calendars?  I have five children and most of them use their iTouch to keep there calendar.   My calendar is on icloud and I'd love it if they could see only their events but I need to see all of them.   Many of the events affect more than one child.

    As follow up to the above question,  I am the person putting items on the calendars.  I am not just trying to see calendars that they are maintaining. 

  • Is there a way to create new events on the new iPhoto app?

    Is there a way to create new events on the new iPhoto app?  I seem to only be able to create albums.  I would really like the app to allow me to do all the same things that I was able to do on my Mac.  I would create events and then sync to all devices.  Can someone please instruct me on how to create new events from the photos imported from the photo stream.
    Thanks for all the help!

    The iPhoto for iOS seems to be aimed at working on photos then sharing them to social media sites or to iCloud for sharing there. iPhoto for iOS does not perform many of the organizing tasks that iPhoto on your Mac does. Many people expected that there would be more capabilities in iPhoto for iOS that would allow it to work more closely with iPhoto on your computer but this is not the case. They are separate apps.

  • TS3999 Is there a way to see the date you invited someone to an event on your calendar?

    Is there a way to see the date you invited someone to an event on your calendar?

    How are you getting to full screen mode? I assume you are using Full Screen mobile add-on?
    Try the following instead:
    * Download Firefox Beta (v22) from google play
    * Navigate to about:config
    * In the search bar look for "dynamic"
    * Toggle 'browser.chrome.dynamictoolbar' to 'true'
    * Close the tab
    Now when using Firefox beta the navigation/loading bar will disappear automatically when you scroll down a page and will reappear when you click on a link.
    Please note that this is an experimental feature so there may be some issues. But I think it works better than the add-on. The feature will eventually come to the standard release version of Firefox for Android.

  • How do i get that little pop up menu with all the editing choices on it that i used to get?  Is there a way to get the editing box to pop up as I make a new event instead of editing an event after i just made it ??????

    How do i get that little pop up menu with all the editing choices on it that i used to get?  Is there a way to get the editing box to pop up as I make a new event instead of editing an event after i just made it ??????

    Michal,
    iCal Help is a good place to start. Here are a couple of examples:

  • Sometimes after creating an event folder on iPhoto, all my pictures in that event will be gone the next time I open iPhoto. Why is this happening? Is there a way to retrieve the missing photos?

    Sometimes after creating an event folder on iPhoto, all my pictures in that event will be gone the next time I open iPhoto. Why is this happening? Is there a way to retrieve the missing photos?
    Most events I make on iphoto will still be there the next time I open iPhoto, while other event FOLDERS will be there, but pictures in it gone.

    What version of iPhoto? Assuming 09 or later:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Repair Database. If that doesn't help, then try again, this time using Rebuild Database.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. (In early versions of Library Manager it's the File -> Rebuild command. In later versions it's under the Library menu.)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  
    Regards
    TD

  • About iCal - is there a way to changes the fonts in iCal, or to modify the fonts in a single event?

    Is there a way to modify the fonts in iCal. I would particularly like to enlarge specific events to make them more noticeable and to even make some of them a bold font to further call attention to them while using iCal. Any help?

    archaeo,
    Unfortunately there are no user options for using other than the default font in iCal. The only font option available in iCal is the "Make Text Bigger/Smaller" View option, but only if you are using the Lion version of iCal.
    I suggest that you provide iCal Feedback.

  • Is there a way to set the default length of appointments/events to 1 hour?

    Is there a way to set the default length of appointments/events to 1 hour?

    No, there's not a way to do that, but it's a good feature request. You can submit feature requests here:
    http://www.adobe.com/go/wish

  • Is there a way to get the actual XML string when using the JAXP SAX Parser?

    Hi All,
    I am using a JAXP SAX xml parser and am looking for a way to get the actual line of xml that is being parsed from within a content handler.
    Here's my scenario. Consider the following example xml document.
    <formCollection>
       <form name="myForm">
          <text/>
          <selection/>
       </form>
       <form name="anotherForm">
          <text/>
       </form>
    </formCollection>My hope is to validate the entire document and then insert an xml string containing each "form" element (and its sub-elements) into a map for later use. My thought was to create a String as each "form" element is being parsed (begining with the form's startElement event and concatenating until the form's endElement event is reached) and then inserting this string into the map. Is there a way to get the actual line of xml that is being parsed, rather than just the element name and attribute values?

    DrClap wrote:
    YouRang wrote:
    2. The first handler would validate the entire XML document, extract the "type" attribute from each <form> element, and place each <form> element and its sub-elements into the map of Strings, using the "type" attribute as the key. The second handler would take a <form> element and parse it into a Form object for the display. This option was the impetus for my question because it relies on the first handler being able to access the entire <form> element XML String and write it to a map.I don't see why you need the raw data from the XML document here. You should already be abstracting your data into Java classes in the first handler, instead of making the second handler do the parsing all over again.Correct, I am not referring to XForms. In this case, it happens that I am using the XML to generate an SWT ScrolledForm object and, thus, the XML element name happens to be named "form." However, the concept/design problem could apply to any type of object and the XML element could be appropriately renamed.
    My experience with XSLT is limited and I haven't done anything with it for several years. With that said, it seems that it is primarily used for generating web content, which wouldn't apply in this case because this is for a client-server application. I could be off base on this one -- if XSLT applies to much broader translations and would be more appropriate for generating Java objects than my current methodology, I could certainly look into it further.
    I apologize that option two didn't make more sense; it is difficult to explain. Yes, optimally the data should be abstracted into Java classes in the first handler. This is really an elaboration that I failed to specify when explaining option one. The problem is that the user can choose to create any number of "forms" of any type. For instance, let's say that from the File -> New menu there are options for seven different types of forms and each form is used to send completely different data. The user can select form1, select form1 again, select form4, and select form7 (or any other combination) and bring up tabs that display the different forms. The user can then enter data and submit each form separately. When the user selects File -> New -> FormX, a SWT ScrolledForm object that corresponds with FormX must be given to the display. Because SWT ScrolledForm objects do not allow a deep copy, I cannot simply read the XML <form> elements at initialization, parse them into ScrolledForm objects, and pass deep copies of the ScrolledForm objects to the display each time the user clicks File -> New -> FormX. The only simple way I see of getting a new copy of a ScrolledForm object is to reparse the appropriate XML <form> element in order to create one each time the user selects File -> New -> FormX. As such, one handler would need to read the entire XML document and parse the <form> elements into a map (or some other data structure) and another handler would need to parse individual <form> elements into SWT ScrolledForm objects. The first handler would be called at initialization and the second handler would be called each time a user clicked on File -> New -> FormX. Once again, this isn't exactly my favorite implementation... but seems the simplest given that there is no way to do a deep copy of an SWT ScrolledForm object. Hopefully that makes a little more sense. No worries if it doesn't -- I just figured I'd throw this out there and see if anyone had a better idea.

  • I create a birthday calendar in iCal and then click on it in iphoto at the begining of the calendar project each year.  Some how the birthday did not populate the photo calendar.  Is there a way to add the birthday iCal calendar into the calendar project?

    I created a birthday calendar to use in iphoto for calendar.  When a new calendar project is started each year, I click on it in.  Some how the birthday did not populate the photo calendar this year.  The photo calendar is almost complete.  Is there a way to add the birthday iCal calendar into the calendar project? I would prefer not to start over.

    Hi,
    If you first select the calendar on the left, so that its background is highlighted blue/grey, when you make a new events they should be added to that calendar.
    Best wishes
    John M

Maybe you are looking for