Controlling events between classes

hello
i know i'm asking a lot, but i couldn't find anything. the problem is i've got a jframe and some panels with buttons.
eg:
class A extends JFrame
getContentPane().add( B ) ;
getContentPane().add( C ) ;
class B extends JPanel
add( button1 ) ;
add( button2 ) ;
class C extends JPanel
add( button3 ) ;
add( button4 ) ;
where do i add ActionListeners? how do i pass information between classes? if button1 is clicked -> class A should know it.
i tried to do this in class A: objectOfB.button1 (access button1 directly) - didn't work - why?
if a button1 is clicked i want to remove the jpanel and replace it with another one. how should i do this?
Thank You All

Check out the java tutorials. There are great examples that show you how to do what you want to do

Similar Messages

  • Broadcast events between classes (objects)

    Hello,
    I'm can't figure out how to broadcast an event to another
    class.
    In actionscript 2 I created 2 classes. The first class called
    the second class to load a file from an url. When the file was
    loaded I used dispatchEvent({type: "fileLoaded", target: this,
    filename: sFilename})
    In the first I simply wrote addEventListener("fileLoaded",
    handleFile)
    But with AS3 this no longer works.
    Can anyone tell me how to accomplish this? Because I can't
    find a clear example and I don't know how to do this.

    In the defintion of your custom event I miss the isEnabled
    part (don't know if that has anything to do with the issue though).
    Below a custom event that works for me
    package Components {
    import flash.events.Event;
    public class ZoomEvent extends Event
    public var isEnabled:Boolean;
    public static const ZOOM:String = 'zoom';
    public var vertical:Boolean = true;
    public var minvalue:Number = 0;
    public var maxvalue:Number = 0;
    public var zoomfactor:Number = 0;
    public function ZoomEvent(type:String,
    isEnabled:Boolean=false) {
    super(type);
    this.isEnabled = isEnabled;
    public override function clone():Event {
    return new ZoomEvent(type, isEnabled);
    Furthermore I have somewhere read in the documentation that
    using custom event should go together with adding an embedded
    statement like: [Event(name="update",
    type="Components.UpdateEvent")] in the class where you use the
    event, but for me it also works without this embedding code (???)
    And is your class XMLData a subclass from a class that
    supports dispatchEvent. I do not know what classes support
    dispatchEvent, maybe all. Then this remark makes no sense.
    Good Lcuk

  • Control flow between classes and a midlet

    Hi All..
    I have somewhat of a strange Question to ask.
    Consider that I have 3 java classes: A B C that are used by a midlet M.
    And the main purpose of A B C is to modify the user interface of M somehow. So maybe A causes a textbox to be displayed, maybe B creates a form etc..
    Also, the midlet implements the Commandlistener interface...hence has an actionCommand method.
    So I am wondering ..if one of these classes (A B C) creates a gui component that has commands, and implements the actionCommand method (from the CommandListener interface), I find that the commands execute properly, but of course, the control is never returned to the main midlet M.
    I would like the classes: A B C to take care of a given representation/apprearance of the display..which may include commands, but I dont know how they can work with the main midlet.
    I cant make the classes pass the commands to the midlet ..because I would like to define their implementation in the actionCommand method..and I dont want the Main midlet to know about the commands that these classes implement...
    Does anyone know how I can implement this? If this makes any sense at all, please send me a reply..I would appreciate any comments.
    cheers all
    cleoppatra

    Hi,
    You mentioned that I should do the following:
    display.setCurrent(midletname)
    SO if my midlet is called Browser, should i say:
    display.setCurrent(Browser)
    I dont know if this is what you menat, but it doensnt work out.
    Can you tell me what you mean?
    cheers

  • Custom Events and Listeners between classes

    I've got a project I've been working on for weeks that I'm
    having yet another problem with. I'm trying to learn AS3 which is
    why it's taking so long but that's not important for this post.
    I wanted to create a custom event class so that I could make
    sure the event does not interfere with other "COMPLETE" events that
    are being passed between classes. In other words, I have a few
    things that need to complete prior to a function being called...
    one is some XML being loaded and another is a font loaded. So, I
    thought I would create a custom FontLoaded class that extends Event
    and make the type something like "FontLoadedEvent.LOADED". That way
    I could listen for the XML "Event.COMPLETE" and this font event
    also.
    Please tell me if I'm going down the wrong path here but I
    don't seem to be getting the dispatched event for my new custom
    event. Also, how does one detect if it's being dispatched other
    than if the eventListener is fired? Any other ways to test
    this?

    You can trace the event to see if it dispatched.
    Also, this is not a good case to create a new event. Custom
    events are used to store additional information. MouseEvent exists
    because Event doesn't have localX, localY, etc. properties. Since
    you don't seem to be throwing additional properties, you can use a
    regular event.
    trace(dispatchEvent(new Event("panelFontsLoaded"));
    addEventListener("panelFontsLoaded", onFontsLoaded);
    Static consts are used to help debug typos. The event type is
    just a string, often stored in a const.

  • Is there a way to dispatch or bubble events between two pop-up windows?

    Hi. I was wondering if there is a way to dispatch custom
    events between two or more pop-up windows created using the
    PopUpManager?
    I understand how to pass an event from one pop-up window to
    the main application (or FrontController) by dispatching the event
    from Application.application under Cairngorm 2.0.
    However, as I understand it, that will only bubble the event
    through the Application chain of visual controls and not to the
    other pop-up windows created using the PopUpManager.
    I tried dispatching the event directly from the pop-up window
    itself, but the other pop-ups still does not seem to receive the
    event.
    It would be nice to be able to do this so that each non-modal
    pop-up can have some awareness with each other.
    Thank you very much in advance.

    If you have just 2 pop-ups you can have them each do a
    addEventListener on the other, listening for the event (custom or
    otherwise).
    If you have an unpredicatable number, then you devise
    something else. Suppose you have 3 pop-ups, p1, p2, and p3. Let's
    say you also have 1 custom event, E1. Any of those pop-ups is
    capable of dispatching an E1 event and you want all of them to
    receive it.
    Create a class that extends EventDispatcher and instantiate
    an object of that class. Each pop-up "registers" with that class,
    something like:
    controller.addEventListener( "E1", handler ); where handler
    is a function in the pop-up.
    When a pop-up wants to dispatch an E1 event, it does it
    through the controller: controller.dispatchEvent( new E1(data) );
    This will automatically dispatch that event to all the
    pop-ups, including the one that dispatched the event. So a pop-up
    will have to examine the event to see if it sent it and perhaps
    ignore it.

  • Control Events

    Hi,
    Can anyone tell me what control events in ABAP are and their syntax.
    Thanks n Regards
    Dinesh

    Hi,
    Control Events are
    1. AT NEW f.
    2. AT END OF f.
    3. AT FIRST.
    4. AT LAST.
    When you sort an extract dataset, control levels are defined in it.The control level hierarchy of an extract dataset corresponds to the sequence of the fields in the HEADER field group. After sorting, you can use the AT statement within a loop to program statement blocks that the system processes only at a control break, that is, when the control level changes.
    AT NEW <f> | AT END OF <f>.
    ENDAT.
    A control break occurs when the value of the field <f> or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field <f> must be part of the HEADER field group.
    If the extract dataset is not sorted, the AT... ENDAT block is never executed. Furthermore, all extract records with the value HEX 00 in the field <f> are ignored when the control breaks are determined.
    The AT... ENDAT blocks in a loop are processed in the order in which they occur. This sequence should be the same as the sort sequence. This sequence must not necessarily be the sequence of the fields in the HEADER field group, but can also be the one determined in the SORT statement.
    If you have sorted an extract dataset by the fields <f1>, <f2>, ..., the processing of the control levels should be written between the other control statements as follows:
    LOOP.
      AT FIRST.... ENDAT.
        AT NEW <f1>....... ENDAT.
          AT NEW <f2>....... ENDAT.
              AT <fgi>..... ENDAT.
              <single line processing without control statement>
          AT END OF <f2>.... ENDAT.
        AT END OF <f1>.... ENDAT.
      AT LAST..... ENDAT.
    ENDLOOP.
    You do not have to use all of the statement blocks listed here, but only the ones you require.
    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/at_itab.htm
    Regards
    Sudheer

  • Passing custom events between modules through parent application

    I have created a custom event that I want to use to pass a string between two modules.  The event looks like this:
        package com.mypackage.events
              import flash.events.Event;
              public class ThumbDeleteEvent extends Event
                        public static const THUMBS_DELETED:String = "thumbsDeleted";
                        public var files:String;
                        public function ThumbDeleteEvent(type:String, files:String)
                        super(type);
                        this.files = files;
                        // Override the inherited clone() method.
                        override public function clone():Event {
                        return new ThumbDeleteEvent(type, files);
    In one module I dispatch the event like so:
        parentApplication.dispatchEvent(new ThumbDeleteEvent("parentApplication.thumbsDeleted", files));
    and in another module I listen for the event like so:
        public function init():void {
                        parentApplication.addEventListener("parentApplication.thumbsDeleted", onThumbsDelete);
    if I use ThumbsDeleteEvent as the type passed in to the listener function like this:
        public function onThumbsDelete(evt:ThumbDeleteEvent):void{
               trace("thumb delete event for thumbs: "+evt.files);
    I get the following error:
        TypeError: Error #1034: Type Coercion failed: cannot convert  com.mypackage.events::ThumbDeleteEvent@26748a31 to com.mypackage.events.ThumbDeleteEvent.
    if I just use Event as the type passed in to the listener function like this:
        public function onThumbsDelete(evt:ThumbDeleteEvent):void{
              if(evt is ThumbDeleteEvent){
                        trace("thumb delete event for thumbs: "+(evt as ThumbDeleteEvent).files);
              }else{
                        var type:XML = describeType(evt);
                        trace(type.toXMLString());
    It works but does not think it is a ThumbDeleteEvent type class (it hits the else statement) the xml output of describe type says its type is:
        type name="com.mypackage.events::ThumbDeleteEvent"
    What is going on here?  If I put a breakpoint in the debugger it says the event is a ThumbDeleteEvent and I can see the files parameter and its right???

    Sorry I have been trying all sorts of stuff and I cut and pasted the wrong version, I meant to put this:
    if I just use Event as the type passed in to the listener function like this:
        public function onThumbsDelete(evt:Event):void{
              if(evt is ThumbDeleteEvent){
                        trace("thumb delete event for thumbs: "+(evt as ThumbDeleteEvent).files);
              }else{
                        var type:XML = describeType(evt);
                        trace(type.toXMLString());
    Then it gets passed to the else condition (it does not recognize it as a ThumbDeleteEvent) and this is the output of the trace:
    <type name="com.helius.events::ThumbDeleteEvent" base="flash.events::Event" isDynamic="false" isFinal="false" isStatic="false">
      <extendsClass type="flash.events::Event"/>
      <extendsClass type="Object"/>
      <constructor>
        <parameter index="1" type="String" optional="false"/>
        <parameter index="2" type="String" optional="false"/>
        <parameter index="3" type="Boolean" optional="true"/>
        <parameter index="4" type="Boolean" optional="true"/>
      </constructor>
      <variable name="files" type="String"/>
      <accessor name="type" access="readonly" type="String" declaredBy="flash.events::Event"/>
      <accessor name="bubbles" access="readonly" type="Boolean" declaredBy="flash.events::Event"/>
      <accessor name="cancelable" access="readonly" type="Boolean" declaredBy="flash.events::Event"/>
      <accessor name="target" access="readonly" type="Object" declaredBy="flash.events::Event"/>
      <accessor name="currentTarget" access="readonly" type="Object" declaredBy="flash.events::Event"/>
      <accessor name="eventPhase" access="readonly" type="uint" declaredBy="flash.events::Event"/>
      <method name="stopImmediatePropagation" declaredBy="flash.events::Event" returnType="void"/>
      <method name="preventDefault" declaredBy="flash.events::Event" returnType="void"/>
      <method name="isDefaultPrevented" declaredBy="flash.events::Event" returnType="Boolean"/>
      <method name="clone" declaredBy="com.helius.events::ThumbDeleteEvent" returnType="flash.events::Event"/>
      <method name="toString" declaredBy="flash.events::Event" returnType="String"/>
      <method name="formatToString" declaredBy="flash.events::Event" returnType="String">
        <parameter index="1" type="String" optional="false"/>
      </method>
      <method name="stopPropagation" declaredBy="flash.events::Event" returnType="void"/>
    </type>
    This causes a TypeError:
    public function onThumbsDelete(evt:ThumbDeleteEvent)
    This causes a null pointer error because myevent is null:
    public function onThumbsDelete(evt:Event):void{
         var myevent:TumbDeleteEvent = (evt as ThumbDeleteEvent);
         var files:String = myevent.files;
    Here is what I see when I put a break point in and debug it:
    I tried upgrading my event extender as you suggested, that had no effect.  I removed the dot notation in the type and it does the exact same thing I.E. dispatching class:
                                                 parentApplication.dispatchEvent(new ThumbDeleteEvent("thumbsDeleted", files));   or
            parentApplication.dispatchEvent(new ThumbDeleteEvent(ThumbDeleteEvent.THUMBS_DELETED, files));
    and receiving class:
         parentApplication.addEventListener("thumbsDeleted", onThumbsDelete);
    I really appreciate your help, I am baffled by this, I have tried everything I can think of for two days and I am ready to start throwing things. 

  • Eventing between multiple IViews

    I have multiple Dynpage IViews on one page. I raise and receive events between the IViews. I can alert the databag or eventObject values. The problem is when I try and write to the IView that has subxcribed to the event.
    ending IView:
    /******  store initial client data   ******/
         EPCM.storeClientData( 'urn:myOwnNameSpace', 'myData', '15' );
         EPCM.storeClientData( 'urn:myOwnNameSpace', 'myData2', '10' )
    /******* set the user name based off of the selected index for Request For *******/
    function setRequest(){  
         var funcName = htmlb_formid+"_getHtmlbElementId";
         func = window[funcName];
         var ddl = eval(func("Request"));  
         var selectedIndex = ddl.getIndex();
         var name = ddl.getValue(selectedIndex);
         EPCM.raiseEvent( 'urn:myOwnNameSpace', 'myRequestFor',  name );
    Receiving IView:
    [code]function myRequestHandler( eventObject ) {
        var passedData = eventObject.dataObject;  
        var temp=EPCM.loadClientData('urn:myOwnNameSpace', 'myData');
        var funcName = htmlb_formid+"_getHtmlbElementId";
         func = window[funcName];
         var myTime = eval(func("myTime"));  
         myTime.setValue(passedData);
    EPCM.subscribeEvent( 'urn:myOwnNameSpace', 'myRequestFor', myRequestHandler);code]
    The alert has the data passed but the values are not written back to the JAVA htmlb objects.
    I did the same thing using JSP DYnpages and it works. I would prefer nto to use the JSP page. Do I have an option

    the problem is not missing the document element value. I have it. I can alert it to the browser. The problem is forcing the value back to the JAVA HTMLB form element within the class.
    The problem is closed. I have gone the JSP route which is working.
    Message was edited by: Tom Mosseau

  • Can we use control events in smartforms

    Hi all,
    I am srinivas. can we use control events in smartforms, I mean at new, at end of ..... if these are not used can you suggest me any alternative....
    Actually my requirement is like a classical report, for which I need to display subtotal and grand totals based on two fields....
    Please help me out in this issue as it is very urgent.
    <b><REMOVED BY MODERATOR></b>
    Thanks in advance....
    Regards,
    Sri...
    Message was edited by:
            Alvaro Tejada Galindo

    Hi Nick,
            Thanks for the reply... it is really very useful for me.
    As I discussed in my earlier mail regarding the output sequence, which should be in the below format.
                                           number       quantity uom      unitprice        amount curr
    plant
           material
                   date
                                             x                 y                    z                      A           
                                             e                 f                     g                      h
                                             p                 q                     r                      s
                   subtotal date..... 1                   2                    3                       4
                   subtotal  material.5                  6                    7                       8
    As you said when I using <b>event of Begin</b> its working fine. but while using the <b>event of end</b>,  I am specifying date and then matnr (sort) its taking(nodes are created mean first matnr and then date) in the reverse order and when I am taking matnr and date it is placing the events(nodes) in the right order but the order date is not triggering.
    can please tell me how to proceed here..
    waiting for your reply..
    Regards,
    Srinivas

  • How to Exchange Data and Events between LabVIEW Executable​s

    I am having some trouble determining how to design multiple programs that can exchange data or events between each other when compiled into separate executables. I will layout the design scenario:
    I have two VIs, one called Status and the other Graph.  The Status VI displays the serial number and status of each DUT being tested (>50 devices).  The Status VI has one timed loop along with a while loop that contains an event structure.  If the user clicks on the DUT Status Cluster the event structure needs to pass the serial number to the Graph VI.  The Graph VI when called fetches the records for the DUT based on the Serial Number and time frame.  This VI is a producer/consumer so the user can change the time frame of the records to display onto the front panel graph.
    I have a couple reasons the VIs need to be separated into independent applications. One being the underlying database fetches tends to slow the threads down between the two VIs; the other is that they may be distributed into separate systems (don't consider this in the design criteria).
    I have been researching the available methods to pass the serial number to the Graph VI.  My initial idea was to us a command line argument, but this does not allow the Status VI to pass another Serial Number to the Graph once it has started (I do not want to allow the user to execute multiple Graph applications because the database query can load down the server).
    Is there a program method that I can implement between the two VIs that will allow me to compile them as two executables, and allow the Status program the repeatedly send an updated serial number event to the Graphs program.
    I have reviewed many methods; Pipes (oglib_pipe), Action Engine, and Shared Variable.  I am not sure which method will give me the ability to use a Event driven structure to inform the Graphs program when to update the serial number.  Any suggestions and tutorials or examples would be greatly appreciated.

    I have used the Action Engine (aka: functional global) approach for many years and it works well. Something to think about is that if you make the event's datatype a variant the only code that will need to know the actual structure of the event will be the function that needs to respond to it. Hence, a single event can service multiple functions.
    Simply create a cluster containing an enum typedef that is a list of the functions that the event will service, and a variant that will be the function event data. From anywhere in the code you can fire the event (via the functional global) by selecting the function from the enum and converting function specific data to a variant. On the receiving end the event handler uses the enum to determine the function that is to get the data and sends the variant to it. The event handler doesn't know or care what the actual event data is so you could in theory add new functions without modifying the event handler.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Events in classes LabVIEW 8.6

    i have class with some member (counter of something)
    and i want to generate a user event when this member has specific values.
    currently i manage to generate the event only if i register the event of the class
    in the Top Vi that use this class
    can i register the event inside the class itself, let say inside the initilize vi that i ave for the this class ?
    thanks
    Solved!
    Go to Solution.

    The question is a little confusing. You can register for the event anywhere you like, but somewhere you pretty much need to have an Event Structure in a running VI waiting for that event to occur.
    What should be aware of these events? Class members
    P.S. On second reading, it seems you might just be asking if you can register the event in a class VI, instead of having to register it in the top-level VI. If that's the case, then yes you can. Just have the Register for Events function inside the Initialize VI of your class and have it output the Event Registration Refnum corresponding to your event.
    Message Edited by Jarrod S. on 11-02-2008 08:48 PM
    Jarrod S.
    National Instruments

  • Eventing between iView and nested iView

    I try to make an Event between an iView and an nested iView. I followed the instruction on page 164 in the reference guide and tried some other things, but it doesn´t work. I make an output Port on the one side, there i could select the fields to be displayed. But when I compose the Input Port , there are no field to see.
    So what make I wrong?

    Hello Marcus,
    the main thing about the desired eventing seems to be that when you have placed your data service in the nested iview you have to create a signal-in port<b> by pulling a data connection out of the input port of the data service</b> to create the input-port of your nested iView. Only this way, the port is filled with the input data of the data service.
    Back in your main iView you can connect the data flow to the newly created port of your nested iView the same way as you connect to a data service. You then should see the input fields of the data service that you placed in the nested iView and be able to assign values to the input fields.
    Hope that helps
    cheers
    Gerhard

  • Is there any Similar between Class.forName() and new operator ???

    Plz tel me is there any Similar between Class.forName() and new operator ??? i have been asked this ques in interview

    You probably should have used the other thread:
    http://forum.java.sun.com/thread.jspa?threadID=792678
    To add a little confusion to the matter...Class objects are in fact objects. They're objects representing classes. So, in a sense, I guess, you could say they're similar -- in each you get an object. But in practice Class objects and all other objects should be considered semantically different unless you're doing some pretty unusual stuff. Also Class.forName is more of a factory method than a constructor.

  • Diffrence between Class.forName() and new Operator

    What is diffrence between class.forName() and new operator.Please tell in much detail.
    Also about classloader.loadclass.
    Suppose the class that we are tring to load with the help of class.forname is not compiled. Again if I make changes at runtime to that class will that get reflected.

    What is diffrence between class.forName() and new
    operator.Please tell in much detail.Class.forName loads a class. The new operator creates a new instance. Apple trees and apples.
    Also about classloader.loadclass.Read the API.
    Suppose the class that we are tring to load with the
    help of class.forname is not compiled.Then you can't load it and get an exception. Read the API.
    Again if I
    make changes at runtime to that class will that get
    reflected.Depends on the changes and when exactly you do them.

  • How to swap the controls contained between two panels?

    I want to swap all the controls contained between two panel? so can anyone please help?
    Thank you in advance

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim LIST1 As New List(Of Control)
    Dim LIST2 As New List(Of Control)
    For Each c As Control In Panel1.Controls
    LIST1.Add(c)
    Next
    For Each c As Control In Panel2.Controls
    LIST2.Add(c)
    Next
    Panel1.Controls.Clear()
    Panel2.Controls.Clear()
    Panel1.Controls.AddRange(LIST2.ToArray)
    Panel2.Controls.AddRange(LIST1.ToArray)
    End Sub

Maybe you are looking for

  • How to save multiple artboards onto one PDF?

    Hi, I've got a large Illustrator file with five artboards, my client asked for seperate PDF's of each artboard which is what I'm used to, but they've also asked for a PDF that shows all the artboards at the same time (basically looking like it does f

  • Clean install vs. time machine recovery after installing new HDD

    Hello All, I have got actually two questions, but I think I only can do one issue at the time. Anyway: Here are my specs and question: 1. I have got a 2010 MacBook Pro with a 320 Gb HDD which seems to be on its way to lala land (crashes almost once e

  • Resizing very high-resolution photos?

      downsizing photos  i want to make a blurb book using photos professionally scanned at high resolution, 7351×4947 pixels at 5250ppi. for the book i want to make they should print at 11.25" and not more than 300ppi. when i downsize them (using image

  • Sales Productions error!!

    Guys did you know on the App Store, Numbers is in the Top Free categories BUT you still have to pay for it.... Apple are not advertising their products to the true value. They should give it to us for FREE if it in the Top Free categories!!

  • Messages opens multiple windows when selecting it from notifications

    I notice that when I click on a new arrival message (iMessage) from notifications popup it will open 4 seperate windows and I can't reply until I close out 3 of the windows. Anyone else seeing this?