Listen for event in own class?

Hi
I dispatch events from models to classes listening. How do you set up an event and listener in the same class?
Eg for the former - a model "MyModel" to class - it's:
public static const MY_VAR:String = "myVar";
triggered by...
dispatchEvent(new Event(MY_VAR));
picked up in another class by...
modelVar.addEventListener(MyModel.MY_VAR, doSomething);
but what if the class that's dispatching also has the listener?
So if MyClass is dispatching the event, along the lines of...
addEventListener(MyClass.MY_VAR, doSomething);
Cheers for taking a look

Very often I'm waiting for a few key items before I can finally do something else. Setting simple flags or checking nulls can help with this.
Often I download multiple data structures (JSON/XML/etc) and I need all of them before I can parse them because the co-depend on each other. URLLoaders finish at different times so I just set a flag for what I need but check if all are complete before I continue each time one finishes.
e.g.
package
     public class IHateWaiting extends EventDispatcher
          public static const MY_VAR:String = "myVar";
          private var _xmlA:XML;
          private var _xmlB:XML;
          public function IHateWaiting()
               // load A
               var ulA:URLLoader = new URLLoader();
               ulA.addEventListener(Event.COMPLETE, _handleFinishedF);
               ulA.load(new URLRequest("http://www.example.com/a.xml"));
               // load B
               var ulB:URLLoader = new URLLoader();
               ulB.addEventListener(Event.COMPLETE, _handleFinishedF);
               ulB.load(new URLRequest("http://www.example.com/b.xml"));
               // listen to self
               addEventListener(IHateWaiting.MY_VAR, _handleAppEventF);
          private function _handleFinishedF(e:Event):void
               if (e.type == Event.COMPLETE)
                    var data:XML = XML(e.target.data);
                    // A or B? any way you can tell
                    if (data.A.length() > 0) _xmlA = data;
                    else if (data.B.length() > 0) _xmlB = data;
                    // event method (requires extra handler or a fake event)
                    if (_xmlA && _xmlB) dispatchEvent(new Event(IHateWaiting.MY_VAR));
                    // preferred direct reference, no handler needed
                    // if (_xmlA && _xmlB) _parseXML();
          private function _handleAppEventF(e:Event):void
               if (e.type == IHateWaiting.MY_VAR) _parseXML();
          private function _parseXML():void
                // parse XML
I recommend the reference version from post #2. It's cleaner because you don't need to double up on functions (handler->reference) like you see above with dispatching. The only purpose for _handleAppEventF() in this case is just to run _parseXML(), which is a useless duplicate function.
I've always kept my handlers free of model-esque logic, so you see me calling a different function from that handler, _parseXML(). This is just because I want my handlers to only handle events and then hand off the work elsewhere.
Instead of dispatching the event, I agree with moccamaximum, run the method directly. Even if it's 2 lines of code to do 1 thing, I think the clarity of it is much cleaner coding. So I would recommend nuking the self-listener in the constructor above. When I have all the data I'm looking for, I'd run the methods in the class directly and If the parent needs to know, I'd dispatch when they complete.
e.g.
          private function _handleFinishedF(e:Event):void
               if (e.type == Event.COMPLETE)
                    var data:XML = XML(e.target.data);
                    // A or B? any way you can tell
                    if (data.A.length() > 0) _xmlA = data;
                    else if (data.B.length() > 0) _xmlB = data;
                    if (_xmlA && _xmlB)
                         // parse first (synchronous)
                         _parseXML();
                         // xml ready, dispatch to parent
                         dispatchEvent(new Event(IHateWaiting.MY_VAR));

Similar Messages

  • Listen for Events from anywhere

    Hello!
    I have an application with a rather complicated component hierarchy.
    How can I have it so that I can listen for events from any component in any component, regardless of who is who's child?
    Thank you!

    You need a broadcasting mechanism.
    Many architecture framework offers this facility, but as a quick hack you can try something like
    public class Broadcaster extends EventDispatcher  ( singleton anti pattern   )
    instance
    then just do Broadcaster.instance.addEventListener or removeEventListener. it's a crappy singleton, but at least it does not hold any global state.
    I've also seen people use Application.application to dispatch/listen globally but really don't like it.
    Note : Use weak references or your views will never be eligible for garbage collections.

  • Sevice Contract - Listener for Events Queue Issue

    Hi,
    The Listener for Events Queue in our Production environment ran very long, It took about 3+ hrs to complete the program. Is there any thing specific that we can check as part of RCA.
    Further there were 'library cache lock' found ... how this can impact the performance and how library cache lock works.
    Regards
    Tauseef E Ahmad

    Hi Team,
    i used the following code for recognizing the key events.
    String javaScriptKeyListener =
    " function keyListener() "
    +" { "
    +" alert(window.event.keyCode) ; } ";
    OAWebBean body = pageContext.getRootWebBean();
    if (body instanceof OABodyBean)
    ((OABodyBean)body).setOnLoad("onKeyPress = javascript:keyListener()");
    but it is not working as expected..
    Any suggestions ??
    Regards
    Sridhar

  • Listen for events from an embedded Swf

    Hi there,
    I have spend so long searching for an answer on the web but can not find any that works, please help!
    I'm not even sure if this is possible but if anyone can guide me in the right direction I would most appreciate it!
    Basically what I would like to do is to load a swf in to my flex application - contrary to my post title it doesnt even have to be embedded - when the loaded swf finishes playing it's animation I want for it to dispatch an event and for flex to listen for that event and trigger a function when the event is captured.
    The animation is made in Flash CS3. I have not used any classes, rather on the last frame I set up an action to dispatch an event like this:
    dispatchEvent(new Event("finishedPlaying"));
    In my Flex Application I load my swf using swfLoader and I add an event listener to it like so:
    mySwfLoader.addEventListener("finishedPlaying", test);
    and my function is like this:
    private function test():void
         trace("it worked!");
    This is not working at all and I'm sure I am missing something but I cant seem to find any straightforward answer on the internet!
    Is it at all possible for a swf made in flash to communicate with flex??
    Since they are both written in AS3, I figured it would be easy but alas!
    If anyone can help me I would most appreciate it, thank you in advance!!
    By the way I have also tried:
    mySwfLoader.content.addEventListener("finishedPlaying", test);
    but no luck....

    You have to wait for the swf to complete loading before adding the event listener.
    When are you adding the event listener?
    mySwfLoader.addEventListener("finishedPlaying", test);
    Have a look at the SWFLoader complete event:
    http://livedocs.adobe.com/flex/3/langref/mx/controls/SWFLoader.html#event:complete

  • Listening to event within custom class

    I've created a custom class that posts to a web page to authorize a user. How can I listen for an event within the custom class?
    This is my code within my main class.
    var customClass:CustomClass = new CustomClass();
    var testingString = customClass.authorize("[email protected]", "password");
    the fuction "authorize" within the customClass looks like this:
    public function authorize(user:String, password:String):void
      jSession = new URLVariables();
                                  j_Loader = new URLLoader();
                                  jSession.j_username = user;
                                  jSession.j_password = password;
                                  jSend.method = URLRequestMethod.POST;
                                  jSend.data = jSession
                                  j_Loader.load(jSend)
    How can I fire an event within my main class once the j_Loader triggers Event.COMPLETE?

    You can fire an event using the dispatchEvent() function.
    In your main class you assign a listener for the event the CustomClass dispatches after it exists.

  • Mxml file listening for event.

    Hi All,
       I'm having following code in my project, here Report.mxml file displays to enter user details like (firstname,lastname,city,state,zip etc). After entering user information there is submit button. When user selects this button it needs to submit this data into database and return REPORT_ID back to confirmation state.
       My problem is that submitting data into database and getting REPORT_ID is taking some time because of that it is not displaying REPORT_ID in Confirmation viewStack. Rather than getting REPORT_ID from RemoteObject, hardcoding(given in red color) this value in my controller then it is displaying REPORT_ID.
      How to wait for event result for displaying confirmation viewStack. Can anyone please suggest me what changes I need to make so that confirmation page will be displayed only after getting REPORT_ID.
    ------------------------------- Report.mxml (begin) ----------------
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
    <mx:Script>
        <![CDATA[
        import mx.controls.Alert;
        import com.westernstates.classes.controller.WesternStatesController;
        import com.westernstates.classes.model.WesternStatesModel;
        import com.westernstates.classes.events.*;
        private var _inquiryIdTxt:String;
        private var _inquiryIdTxtChanged:Boolean;
        public function set inquiryIdTxt(value:String):void
           _inquiryIdTxt = value;
           _inquiryIdTxtChanged = true;
           invalidateProperties();
           invalidateSize();
        override protected function commitProperties():void
          super.commitProperties();
          if (_inquiryIdTxtChanged)
              Alert.show("Inside commitProperties 1",_inquiryIdTxt);
             inquiryIdVal.text = _inquiryIdTxt;
             //inquiryIdVal.text = "1234"
             _inquiryIdTxtChanged = false;
        public function init():void{
            Alert.show("Inside newreport init mxml");
            myViewStack.selectedChild = newReport;
            Confirmation.visible=false;
            // Reset the value too.
            first_name.text = "";
            last_name.text = "";
            street_address.text = "";
            street_address2.text = "";
            city.text = "";
            state.text = "";
            zip.text = "";
            public function submitInquiry(evt:Event):void{
            var chk_speed_up:String = "";
            WesternStatesModel.inquiryConsumer.first_name = first_name.text;
              WesternStatesModel.inquiryConsumer.last_name = last_name.text;
              WesternStatesModel.inquiryConsumer.street_address = street_address.text;
              WesternStatesModel.inquiryConsumer.street_address2 = street_address2.text;
              WesternStatesModel.inquiryConsumer.city = city.text;
              WesternStatesModel.inquiryConsumer.state = state.text;
              WesternStatesModel.inquiryConsumer.zip = zip.text;
              myViewStack.selectedChild = Confirmation;
              newReport.visible=false;   
             this.dispatchEvent(new NewReportEvent());        
              //inquiryIdVal.text = _inquiryIdTxt;
              inquiryIdVal.text = WesternStatesModel.inquiryConsumer.inquiry_id;
        ]]>
    </mx:Script>
        <mx:ViewStack id="myViewStack" width="100%" height="100%" creationPolicy="all" >
        <mx:Canvas id="newReport" height="100%" width="100%" visible="true">
        <mx:Label x="10" y="10" text="NEW REPORT"  fontSize="18" fontWeight="bold" color="#F07012"/>
        <mx:TitleWindow width="100%" height="100%" layout="absolute" title="Create A New Report" fontWeight="normal" fontSize="13" y="38" x="0">
         <mx:Canvas height="100%" width="100%">
         <mx:VBox width="100%" height="100%">
             <mx:HBox>
                 <mx:Label text="Consumer Information: " fontSize="12" fontWeight="bold" color="#34B05D"/>
             </mx:HBox>
             <mx:HBox>
                 <mx:Label text="Report Type: " fontWeight="normal"/>
                 <mx:Label text="Phone" fontWeight="bold"/>
             </mx:HBox>
             <mx:HBox width="100%">
                 <mx:Label width="25%"  text="First Name:" fontWeight="normal"/>
                 <mx:TextInput width="25%" id="first_name"/>
                 <mx:Label  width="25%" text="Last Name:" fontWeight="normal"/>
                 <mx:TextInput width="25%" id="last_name"/>
             </mx:HBox>
             <mx:HBox width="100%">
                 <mx:Label  width="25%" text="Address1: " fontWeight="normal"/>
                 <mx:TextInput width="25%" id="street_address"/>
                 <mx:Label  width="25%" text="Address2:" fontWeight="normal"/>
                 <mx:TextInput width="25%" id="street_address2"/>
             </mx:HBox>
             <mx:HBox width="100%">
                 <mx:Label  width="25%" text="City: " fontWeight="normal"/>
                 <mx:TextInput width="25%" id="city"/>
                 <mx:Label  width="25%" text="State:" fontWeight="normal"/>
                 <mx:TextInput width="25%" id="state"/>
             </mx:HBox>
             <mx:HBox width="100%">
                 <mx:Label  width="25%" text="Zipcode: " fontWeight="normal"/>
                 <mx:TextInput width="25%" id="zip"/>
                 <mx:Label  width="25%" text="Phone"/>
                 <mx:TextInput width="25%" id="phone"/>
             </mx:HBox>
             <mx:HBox width="100%" horizontalAlign="center">
                 <mx:Button label="SUBMIT REPORT" id="submit_search" click="submitInquiry(event)" fillColors="#34B05D"/>
             </mx:HBox>        
            </mx:VBox>
        </mx:Canvas>
        </mx:TitleWindow>
        </mx:Canvas>
            <mx:Canvas id="Confirmation" width="100%" height="100%">
            <mx:Label x="10" y="10" text="NEW REPORT"  fontSize="18" fontWeight="bold" color="#F07012"/>
            <mx:TitleWindow width="100%" height="132" layout="absolute" title="Create A New Report" fontWeight="normal" fontSize="13" y="38" x="0">
            <mx:VBox width="100%" height="81">
                 <mx:HBox>
                     <mx:Label text="Submission Confirmation:" fontSize="12" fontWeight="bold" color="#34B05D"/>
                 </mx:HBox>
                 <mx:HBox>
                     <mx:Label text="Report has been created successfully with Report ID:"/>
                     <mx:Label id="inquiryIdVal" fontSize="12" fontWeight="bold" color="#34B05D"/>
                 </mx:HBox>
             </mx:VBox>
            </mx:TitleWindow>
            </mx:Canvas>
        </mx:ViewStack>
    </mx:Canvas>
    ------------------------------- Report.mxml (end)   -----------------
    ------------------------------- NewReportEvent.as( begin) ---------------
    package com.westernstates.classes.events
      import flash.events.Event;
      // This custom event should be dispatched if the user
      // successfully logs into the application.
      public class NewReportEvent extends Event{   
        public static const REPORT:String = "report"; 
        public function NewReportEvent(){
          super(NewReportEvent.REPORT);
    ------------------------------- NewReportEvent.as( end)   ----------------
    ------------------------------- WesternStatesController.as (begin) ------------
       public class WesternStatesController extends UIComponent{
        public function WesternStatesController(){
          addEventListener( FlexEvent.CREATION_COMPLETE, init);
        // Add event listeners to the system manager so it can handle events
        // of interest bubbling up from anywhere in the application.
        private function init( event:Event ):void{    
         systemManager.addEventListener(NewReportEvent.REPORT, newInquiry, true);
          login(new LoginEvent(LoginEvent.LOGIN));
            public function newInquiry(evt:NewReportEvent):void{
                 Alert.show("Inside newInquiry", evt.type);
                 addNewInquiry();
                 //getNewInquiryResult();
             }//End of newInquiry
             public function addNewInquiry():void
                 ro = new RemoteObject();
                 setUpAmfChannel();
                 ro.destination = "manageInquiryService";
                 ro.addEventListener("fault", faultHandler);      
                 ro.createInquiry.addEventListener("result", getNewInquiryResultHandler);
                 Alert.show("Before addNewInquiry");      
                 ro.createInquiry(WesternStatesModel.inquiry,WesternStatesModel.inquiryConsumer);
             }//End of addNewInquiry
             public function getNewInquiryResultHandler(event:ResultEvent):void
                     WesternStatesModel.inquiryConsumer.inquiry_id = event.result as String;
                    //WesternStatesModel.inquiryConsumer.inquiry_id = "09S-1234";  UNCOMMENT     
             }//End of getNewInquiryResultHandler
    ------------------------------- WesternStatesController.as (end) ---------------
    Thanks in advance.
    Regards,
    Sharath.

    Can someone please tell me how to add event handler to show REPORT_ID before displaying confirmation page. Confirmation page should be displayed once data saved successfully and getting REPORT_ID back from server.
    How to set variables for .mxml from action script(.as) file.
    Thanks,
    Sharath.

  • Listen for events in another Gui class

    Most of the GUIs I have written to date have consisted of either a single class or multiple self-contained classes - mainly extensions of JPanel with JButtons etc to perform certain tasks.
    Now I want to be able to click a JButton in one class which will invoke a method in another.
    The code is too lengthy to post here but this is the general layout:
    JFrame Simulation_GUI contains a JPanel (panelMain) which is set as the content pane
    panelMain contains two GUI classes which extend JPanel;
    buttonPane > contains a number of JButtons, including the one I want to click
    loadingPane > contains the method (which takes a Hastable as an argument) I want to run
    All three panels are declared in the main class which extends JFrame, so I know that from there I can simply call;
    loadingPanel.runLoads(htData); but how do I do this from the JButton on the buttonPane.
    Any assistance greatly appreciated as I have little enough hair at the moment and can't afford to tear much more out.
    Thanks in advance

    Class GUI1 {
    //Display all the buttons.
    public void init() {
    Button.addActionListener(new
    ener(new SomeClass(this));
    Class SomeClass implements ActionListener {
    GUI1 gui = null;
    SomeClass(GUI1 gui) {
    this.gui = gui;
    public void actionPerformed(ActionEvent e) {
    //Do all your process here
    gui.setTable(table);    //table would be ur
    ould be ur hashtable
    }Cheers
    -PThis didn't fully answer my question but did two things:
    1. Told me that it is at least possible and it is just me having a senior moment,
    2. Sent me on the right road to finding a solution
    With additional help from the following post I have sorted my problem. Basically I had to centrallise the event handling into a different class. This was instantiated by the main GUI class and passed to the other GUI components as an argument.
    http://forum.java.sun.com/thread.jspa?threadID=576012&messageID=2881969
    Simple when you know how...!
    prashanth_kuppur - have some Duke Dollars on me and thanks for the poke in the right direction.

  • JTextfield  listening for changes from other class

    Hi,
    Assuming I have a Jtextfield in one of the class1 extend Jframe,
    how do I update the jtextfield so that it could up make accessible by other class and continuously updated to reflect the input for value rom another class2.
    In other words very much similar to the observable model view concept
    class 1 may be look like
    private void initComponents() {
    jTextField1 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextField1.setEditable(false);
    class 2 may be look similar to the following
    public void out_1(){
    setStop1("N");
    for (int i=1;i<100;i++){
    class_1.getJTextField1().setText(String.valueOf(i)); // System.out.println(i);
    setOuti(i);
    setStop1("N");

    HI,
    I have attempted with the following coding , test 1 the source display generated using Netbeans GUI , t est2 the worker code ,and mybean the bean , so far nothing seems to work .
    I have not try the threaded swing concept as I am not familar with the concurrency but i am not sure whether propertylistener will do the job or not
    In summary , list of method employed are :
    binding the jtextfield1 to a bean,
    jtextfield add document listener ,
    Coding objective
    1. Test 1 defined jtexfield1 and jbutton
    2 Jbutton added actionlistener , where upon click,
    Execute Test 2 which will assign a series of integer to the bean , own setters & getters, Output is achieved via Test 1 jtextfield1 supposingly to display all the running number from 1 to 99 continuously until the test2 out_1 method finished the execution
    Anyone could provide the assistance .
    Thank
    * Test_1.java
    * Created on July 25, 2007, 9:23 PM
    package sapcopa;
    import java.beans.PropertyChangeListener;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    import javax.swing.text.Document;
    import sapcopa.MyBean.*;
    public class Test_1 extends javax.swing.JFrame {
    /** Creates new form Test_1 */
    // private Test_2 t2=new Test_2();
    private String input_txt;
    public Test_1() {
    myBean1=new MyBean();
    myBean1.addPropertyChangeListener(new java.beans.PropertyChangeListener(){
    public void propertyChange(java.beans.PropertyChangeEvent evt) {
    bean_chg(evt);
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
    myBean1 = new sapcopa.MyBean();
    jTextField1 = new javax.swing.JTextField();
    jTextField1.getDocument().addDocumentListener(new MyDocumentListener());
    jButton1 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextField1.setEditable(false);
    jTextField1.setText(myBean1.getRecord_Process());
    jTextField1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
    public void propertyChange(java.beans.PropertyChangeEvent evt) {
    txt1_chg(evt);
    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    But1(evt);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(19, 19, 19)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createSequentialGroup()
    .addGap(32, 32, 32)
    .addComponent(jButton1)))
    .addContainerGap(131, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(21, 21, 21)
    .addComponent(jButton1)
    .addContainerGap(216, Short.MAX_VALUE))
    pack();
    }// </editor-fold>//GEN-END:initComponents
    private void txt1_chg(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txt1_chg
    // TODO add your handling code here:
    //myBean1=new MyBean();
    try {
    jTextField1.setText(myBean1.getRecord_Process());
    } catch (Exception e){
    e.printStackTrace();
    }//GEN-LAST:event_txt1_chg
    private void bean_chg(java.beans.PropertyChangeEvent evt){
    jTextField1.setText(myBean1.getRecord_Process());
    private void But1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_But1
    //getJTextField1().getDocument().addDocumentListener(new MyDocumentListener());
    Test_2 t2=new Test_2();
    t2.out_1();
    try{
    System.out.println("Button 1 mybean->"+myBean1.getRecord_Process());
    } catch (Exception e){
    e.printStackTrace();
    // TODO add your handling code here:
    }//GEN-LAST:event_But1
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Test_1().setVisible(true);
    public javax.swing.JTextField getJTextField1() {
    return jTextField1;
    public void setJTextField1(javax.swing.JTextField jTextField1) {
    this.jTextField1 = jTextField1;
    class MyDocumentListener implements DocumentListener {
    final String newline = "\n";
    public void insertUpdate(DocumentEvent e) {
    // updateLog(e, "inserted into");
    String vstr=myBean1.getRecord_Process().toString();
    jTextField1.setText(vstr);
    public void removeUpdate(DocumentEvent e) {
    //updateLog(e, "removed from");
    String vstr=myBean1.getRecord_Process().toString();
    jTextField1.setText(vstr);
    public void changedUpdate(DocumentEvent e) {
    //Plain text components don't fire these events.
    String vstr=myBean1.getRecord_Process().toString();
    jTextField1.setText(vstr);
    public void updateLog(DocumentEvent e, String action) {
    Document doc = (Document)e.getDocument();
    int changeLength = e.getLength();
    // jTextField1.setText(String.valueOf(changeLength));
    String vstr=myBean1.getRecord_Process().toString();
    jTextField1.setText(vstr);
    public String getInput_txt() {
    return input_txt;
    public void setInput_txt(String input_txt) {
    this.input_txt = input_txt;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JTextField jTextField1;
    private sapcopa.MyBean myBean1;
    // End of variables declaration//GEN-END:variables
    * Test_2.java
    * Created on July 25, 2007, 9:26 PM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package sapcopa;
    import sapcopa.MyBean.*;
    public class Test_2 {
    private Test_1 t1=new Test_1();
    private int outi;
    private String stop1;
    MyBean mybean;
    /** Creates a new instance of Test_2 */
    public Test_2() {
    public void out_1(){
    setStop1("N");
    mybean=new MyBean();
    for (int i=1;i<100;i++){
    mybean.setRecord_Process(String.valueOf(i));
    setOuti(i);
    setStop1("N");
    setStop1("Y");
    public int getOuti() {
    return outi;
    public void setOuti(int outi) {
    this.outi = outi;
    public String getStop1() {
    return stop1;
    public void setStop1(String stop1) {
    this.stop1 = stop1;
    * MyBean.java
    * Created on July 24, 2007, 12:00 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package sapcopa;
    import javax.swing.JTextField;
    public class MyBean {
    /** Creates a new instance of MyBean */
    public MyBean() {
    * Holds value of property record_Process.
    private JTextField txt_rec_process;
    private String record_Process;
    * Utility field used by bound properties.
    private java.beans.PropertyChangeSupport propertyChangeSupport = new java.beans.PropertyChangeSupport(this);
    * Adds a PropertyChangeListener to the listener list.
    * @param l The listener to add.
    public void addPropertyChangeListener(java.beans.PropertyChangeListener l) {
    propertyChangeSupport.addPropertyChangeListener(l);
    * Removes a PropertyChangeListener from the listener list.
    * @param l The listener to remove.
    public void removePropertyChangeListener(java.beans.PropertyChangeListener l) {
    propertyChangeSupport.removePropertyChangeListener(l);
    * Getter for property record_Process.
    * @return Value of property record_Process.
    public String getRecord_Process() {
    return this.record_Process;
    * Setter for property record_Process.
    * @param record_Process New value of property record_Process.
    public void setRecord_Process(String record_Process) {
    String oldRecord_Process = this.record_Process;
    this.record_Process = record_Process;
    propertyChangeSupport.firePropertyChange("record_Process", oldRecord_Process, record_Process);
    * Holds value of property rec_Match.
    private String rec_Match;
    * Getter for property rec_Match.
    * @return Value of property rec_Match.
    public String getRec_Match() {
    return this.rec_Match;
    * Setter for property rec_Match.
    * @param rec_Match New value of property rec_Match.
    public void setRec_Match(String rec_Match) {
    String oldRec_Match = this.rec_Match;
    this.rec_Match = rec_Match;
    propertyChangeSupport.firePropertyChange("rec_Match", oldRec_Match, rec_Match);
    public JTextField getTxt_rec_process() {
    return txt_rec_process;
    public void setTxt_rec_process(JTextField txt_rec_process) {
    JTextField oldTxt_rec_process=this.txt_rec_process;
    this.txt_rec_process = txt_rec_process;
    propertyChangeSupport.firePropertyChange("txt_rec_process", oldTxt_rec_process, txt_rec_process);
    }

  • ICal no longer listening for event notifications in 10.5.4

    Up until 10.5.4, iCal would automatically add todo's and calendar events to its display when an event was created from an external app using the CalendarStore framework...
    Not anymore... The events are created, but you need to click on a different view to get iCal to realize something has been added to the calendar
    What's the normal way to submit a bug report to Apple on this?

    Hi,
    the normal way is to submit feedback over here: http://www.apple.com/feedback/ical.html
    Björn

  • Listening for an event in main from a component

    Hi
    Ok so i have a Flash Builder project 4.5 that i created in Flash Catalyst thats draws all its data from MySql and four months into the build, as this is my first web project im noticing that when the page loads up in the browser it loads everything at once! and as im hoping to reuse some of the same components for diffrent tasks i assume that if i put the data retrivail under events that happen within the web page this will hopeful control the data flow as well as showing the correct data depending on CurrentState!
    The problem that im having is that my buttons are in my Main Application and the data retrival process is in my components! so i was trying to create addEventListener(MouseEvent.CLICK events in a component that was listening for events in my Main application. i have search the internet but every one is talking about the process in the main or component but not both!
    Does anyone know what im talking about and could you please share some light please

    Do you ever get to a point in programming where you think that perhaps i have choosen the wrong hobby to get infatuated about
    That code worked really well targetplanet but it had a side effect that just makes me nutts lol
      as it triggered a mouse event function in the component that was initialized in Main and just made my web site go nuts . the component that we initialized was a skin but its itemRenderer component that followed had the mouse event! perhaps i better start again with me learning perhaps i missed something
    or perhaps i should just have one component to one job instead of trying to be clever and mutitask with less components!

  • Listening to Events from inside loaded swf

    In Flash Builder 4 I have a swfLoader with which I load swf files. The swf files that get loaded get created in Flash Pro, and I would like to be able to listen for events from the level that they get loaded from. What would I have to specify in the Flash file for the path? Can't seem to be able to specify the right path.
    Thanks a lot for any help!

    I wouldnt say this is elegant but we have been having issues gaining direct access to the SWF's loaded in via OSMF. However I have done setups where I dispatch an event from a SWF and have it bubble up and catch it on the MediaContainer level. Not elegant but works- otherwise may need to make a custom MediaElement and bypass the SWFElement to gain tighter control - seems like there should be a better way, but I havnt found it.

  • Listen for an events for Swing objects in a separate class?

    Hi all, sorry if this is in the wrong section of the forum but since this is a problem I am having with a Swing based project I thought i'd come here for help. Essentially i have nested panels in separate classes for the sake of clarity and to follow the ideas of OO based development. I have JPanels that have buttons and other components that will trigger events. I wish for these events to effect other panels, in the Hierachy of my program:
    MainFrame(MainPanel(LeftPanel, RightPanel, CanvasPanel))
    Sorry I couldnt indent to show the hierarchy. Here LeftPanel, RightPanel and CanvasPanel are objects that are created in the MainPanel. For example i want an event to trigger a method in another class e.g. LeftPanel has a button that will call a method in CanvasPanel. I have tried creating an EventListner in the MainPanel that would determine the source and then send off a method to the relevant class, but the only listeners that respond are the ones relevant to the components of class. Can I have events that will be listened to over the complete scope of the program? or is there another way to have a component that can call a method in the class that as an object, it has been created in.
    Just as an example LeftPanel has a component to select the paint tool (its a simple drawing program) that will change a color attribute in the CanvasPanel object. Of course I realize i could have one massive Class with everything declared in it, but I'd rather learn if it is possible to do it this way!
    Thanks in advance for any help you can offer
    Lawrence
    Edited by: insertjokehere on Apr 15, 2008 12:24 PM

    Thanks for the response, ive added ActionListneres in the class where the component is, and in an external class. The Listeners work inside the class, but not in the external class
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    public class LeftPanel extends JPanel implements ActionListener {  
        /* Constructing JButtons, null until usage of the constructor */
        JButton pencilBut;
        JButton eraserBut;
        JButton textBut;
        JButton copyBut;
        JButton ssincBut;
        JButton ssdecBut;
        ActionListener a = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.print("\nNot supported yet.");
        /* The Top Panel contains the title of program */
        public LeftPanel(Dimension d){
            /* Sets up the layout for the Panel */
            BoxLayout blo = new BoxLayout(this,BoxLayout.Y_AXIS);
            this.setLayout(blo);
            /* Sets Up the Appearance of the Panel */
            this.setMinimumSize(d);
            this.setBackground(Color.RED);
            this.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
            /* Pencil Tool */
            pencilBut = new JButton("Pencil");
            pencilBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            pencilBut.setActionCommand("pencil");
            pencilBut.addActionListener(a);
            this.add(pencilBut);
            /* Eraser Tool */
            eraserBut = new JButton("Eraser");
            eraserBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            eraserBut.addActionListener(a);
            this.add(eraserBut);
            /* Text Tool */
            textBut = new JButton("Text");
            textBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            textBut.addActionListener(a);
            this.add(textBut);
            /* Copy Previous Page */
            copyBut = new JButton("Copy Page");
            copyBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            copyBut.addActionListener(a);
            this.add(copyBut);
            /* Stroke Size Increase */
            ssincBut = new JButton("Inc");
            ssincBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            ssincBut.addActionListener(a);
            this.add(ssincBut);
            /* Stroke Size Decrease */
            ssdecBut = new JButton("Dec");
            ssdecBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            ssdecBut.addActionListener(a);
            this.add(ssdecBut);
            System.out.print("\nLeftPanel Completed");
        public void actionPerformed(ActionEvent e) {
            System.out.print("\nAction Performed");
        }But this is not picked up in my external class here
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    public class MainPanel extends JPanel implements ActionListener {
        /* Creates a new the main JPanel that is used in the FlipBookFrame to contain all of the elements */
        public MainPanel(){
            /* TopPanel constraints*/
            tpcs.gridx = 1;
            tpcs.gridy = 0;
            tpcs.gridwidth = 1;
            tpcs.gridheight = 1;
            tpcs.fill = GridBagConstraints.BOTH;
            tpcs.weightx = 0.0;
            tpcs.weighty = 1.0;
            /* LeftPanel Constraints*/
            lpcs.gridx = 0;
            lpcs.gridy = 0;
            lpcs.gridwidth = 1;
            lpcs.gridheight = 3;
            lpcs.fill = GridBagConstraints.BOTH;
            lpcs.weightx = 1.0;
            lpcs.weighty = 1.0;
            /* CentrePanel Constraints*/
            cpcs.gridx = 1;
            cpcs.gridy = 1;
            cpcs.gridwidth = 1;
            cpcs.gridheight = 1;
            cpcs.fill = GridBagConstraints.NONE;
            cpcs.weightx = 0.0;
            cpcs.weighty = 0.0;
            /* RightPanel Constraints*/
            rpcs.gridx = 2;
            rpcs.gridy = 0;
            rpcs.gridwidth = 1;
            rpcs.gridheight = 3;
            rpcs.fill = GridBagConstraints.BOTH;
            rpcs.weightx = 1.0;
            rpcs.weighty = 1.0;
            /* BottomPanel Constraints*/
            bpcs.gridx = 1;
            bpcs.gridy = 2;
            bpcs.gridwidth = 1;
            bpcs.gridheight = 1;
            bpcs.fill = GridBagConstraints.BOTH;
            bpcs.weightx = 0.0;
            bpcs.weighty = 1.0;   
            this.setLayout(gblo);   //Sets the Layout of the panel to a GridBagLayout
            this.add(tp, tpcs); //Adds the TopPanel to the MainPanel using the TopPanel layout
            this.add(lp, lpcs); //Adds the LeftPanel to the MainPanel using the LeftPanel layout
            this.add(cp, cpcs); //Adds the CanvasPanel to the MainPanel using the CanvasPanel layout
            this.add(rp, rpcs); //Adds the RightPanel to the MainPanel using the RightPanel layout
            this.add(bp, bpcs); //Adds the BottomPanel to the MainPanel using the BottomPanel layout
            gblo.layoutContainer(this); //Lays Out the Container
        public PanelSizes getPanelSizes(){
            return ps;
        public void actionPerformed(ActionEvent e) {
            System.out.print("\nExternal Class finds event!");
            /*String command = e.getActionCommand();
            if (command.equals("pencil")){
                System.out.print("\nYESSSSSSSSSSSSSSSSSSSSS!");
        /* Create of objects using the PanelSizes funtions for defining the */
        PanelSizes ps = new PanelSizes();   //Creates a new PanelSizes object for sizing the panel
        CanvasPanel cp = new CanvasPanel(ps.getCentrePanelDimension()); //Creates a new Canvas Panel
        TopPanel tp = new TopPanel(ps.getHorizontalPanelDimension()); //Creates the TopPanel
        BottomPanel bp = new BottomPanel(ps.getHorizontalPanelDimension()); //Creates the BottomPanel
        LeftPanel lp = new LeftPanel(ps.getVerticalPanelDimension()); //Creates the LeftPanel
        RightPanel rp = new RightPanel(ps.getVerticalPanelDimension());   //Creates the RightPanel
        /* I have chosen to create individual constraints for each panel to allow for adding of all
         components a the end of the constructor. This will use slightly more memory but gives clarity
         in the code */
        GridBagConstraints cpcs = new GridBagConstraints();
        GridBagConstraints tpcs = new GridBagConstraints();
        GridBagConstraints bpcs = new GridBagConstraints();
        GridBagConstraints lpcs = new GridBagConstraints();   
        GridBagConstraints rpcs = new GridBagConstraints();
        GridBagLayout gblo = new GridBagLayout();
    }Any help will be greatly appreciated :-)

  • Listening for an event outside of the object...

    Hey, I spent a lot of my day trying to figure out how to
    listen for an event outside of an instantiated object of my own.
    I made my own class called
    Link. When my Link class is instantiated, a Loader object
    (var loader:Loader) is added and it loads a user-specified external
    PNG file. I want to track the Event.COMPLETE event OUTSIDE of my
    Link class, like in my FLA's Actionscript.
    So, I tried a few things without any luck, and by these you
    might get the idea of exactly what I'm trying to do:
    var link1:Link = new Link(...);
    link1.loader.addEventListener(Event.COMPLETE, handler);
    That didn't work, so I tried:
    var link1.Link = new Link(...);
    var loader = link1.getChildByName("loader") as Loader;
    loader.addEventListener(Event.COMPLETE, handler);
    ... that didn't work either. :(
    Any ideas?
    If I am taking the completely wrong approach please do let me
    know. If there's ANY way to know WHEN my loader has completed
    loading its image outside of my Link class...
    Thanks!
    ~ Andrew Merskin

    Let your Link class handle the Loader events. When
    Event.COMPLETE fires,
    just redispatch the event or dispatch a custom event.
    Example 1:
    link1.addEventListener("ALLDONELOADING", linkEventHandler);
    function linkEventHandler(event:Event)
    if(event.type == "ALLDONELOADING")
    // do something or nothing at all
    // Inside your link class you are listening for the load
    complete
    function loadCompleteHandler(event:Event)
    dispatchEvent(new Event("ALLDONELOADING")));
    Example 2:
    link1.addEventListener(Event.COMPLETE, linkEventHandler);
    function linkEventHandler(event:Event)
    if(event.type == Event.COMPLETE)
    // do something or nothing at all
    // Inside your link class you are listening for the load
    complete
    function loadCompleteHandler(event:Event)
    dispatchEvent(event);

  • How to create many objects listening for one event

    I'm experimenting with the EventDispatcher class and I have a
    test class working. I want to use a loop to create a variety of
    movie clips that all listen for an event that gets dispatched every
    half a second. I have the event dispatching properly. My problem is
    that when creating the objects, the temporary variable I use to
    hold each created object has a life that extends beyond the loop in
    which it is instantiated. Rather than all five created objects
    changing color, only the last one changes color (see the code
    below--it lives on the first frame of an FLA file).
    This is not entirely surprising when I look at the code --
    'this' refers to the global scope and 'square' refers to the last
    created object that it pointed to. Here's the resulting trace:
    handler runing, square name is square 4
    this class name is global
    handler runing, square name is square 4
    this class name is global
    handler runing, square name is square 4
    this class name is global
    handler runing, square name is square 4
    this class name is global
    handler runing, square name is square 4
    this class name is global
    How can I modify this code so that each square object changes
    its own color?

    graphics.clear in the context of that function handler in my
    code would refer not to the squares but to the global scope,
    wouldn't it? In which case you'd be clearing all the graphics from
    your top level movie. I tried changing 'square.graphics' to just
    'graphics' in my handler and my squares just remained the original
    steady black.
    Your code doesn't use a loop and therefore isn't re-using a
    variable. You've escaped my 'logical errors' through brute force.
    (BTW, I think my code would work in AS2 if I used the old-school
    draw methods). Suppose you had to create 100 objects? Would you
    want to manually instantiate each one, typing that function over
    and over again? You'd have 500 lines of highly redundant code!
    Maybe try your example using a loop instead? I think you'll
    find it's pretty tough to sneak any vars like 'i' or 'square' from
    the global scope into the handler--the handler refers to the
    living, breathing variable rather than it's value at the time the
    handler was instantiated. Furthermore, you can't sneak any
    information about the square into your handler via the event object
    because the event object is created in a totally different place.

  • Listening for change events on a JTable

    Hi
    me = Java newbie!
    Well I've been building an app to read EXIF data from JPEG files using the imageio API and Swing. Learning both along the way.
    Stumbling block is that I am outputting the EXIF data into a JTable, inside a JScrollPane. These 2 components then become associated with a JInternalFrame container of the class MyInternalFrame.
    Works!
    Next job is to enable user to select a row in the table which then displays the image file.
    I know I can use ListSelectionEvent to detect a row selection and that 2 events are fired.
    I put some code into MyInternalFrame class to register a ListSelectionEvent, but I can't see how to reference MyInternalFrame from within this code....see below:
    package EXIFReader;
    import java.io.File;
    import java.io.FilenameFilter;
    import javax.swing.JInternalFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    //This class constructs a table and displays it in a JInternalFrame
    public class MyInternalFrame extends JInternalFrame {
    static int openFrameCount = 0;
    static final int xOffset = 30, yOffset = 30;
    File file;
    File[] directoryMembers = null;
    public MyInternalFrame(File aFile) { //aFile rererences a directory containing jpeg files//
    super(null,
    true, //resizable
    true, //closable
    true, //maximizable
    true);//iconifiable
    file = aFile;
    //Set the window's location.
    this.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
    FilenameFilter filter = new FilenameFilter() {
    public boolean accept(File dir, String name) {
    return name.endsWith(".jpg");}};//Filter out any files in the directory that ain't jpegs
    directoryMembers = file.listFiles(filter);
    int i = 0;
    String[][] tableData= new String [directoryMembers.length][5];
    String[]headers = new String[]{"File Name","Date Taken",
    "F-Number","Exposure",
    "Flash Settings"};
    for (File dirfile: directoryMembers)
    try {
    if(dirfile!=null){
    tableData[i] = new ExifReader(dirfile).getEXIFData();//populate the table with jpeg file names
    i++;}}
    catch (Exception ex) {
    System.out.print("Error" + ex);
    if (tableData[0] != null){
    final JTable myTable = new JTable(tableData,headers);
    this.setSize(900,(50+(directoryMembers.length)*19));
    myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.getContentPane().add(new JScrollPane(myTable),"Center");//add the JTable and JScrollPanel to this MyInternal Frame and display it! - cool it works!
    ListSelectionModel myLSM = myTable.getSelectionModel();
    myLSM.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent le) {
    int[] rows = myTable.getSelectedRows();//want to respond to selections and then display the image as a JInternalFrame but got confused about references from within this listener - need help!
    Any gentle nudges?!
    P
    I can respond to these events using a JFrame, but how can I display the image in a JInternalFrame?

    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    To get better help sooner, post a [_SSCCE_|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.
    db

Maybe you are looking for