Results 1 to 5 of 5

Thread: How to write a Property Change Listener in Java?

  1. #1
    Join Date
    Jul 2006
    Posts
    182

    How to write a Property Change Listener in Java?

    Hi folks,
    Last time your solutions were really useful for me, so thought that this is the right place to post my query. Now I am stuck with the property change listener in Java.!! I know that this occur whenever the value of a bound property changes. But since I don't know much about the beans, I am not able to use this property. So requesting you all guys, please tell me how to write a Property Change Listener in Java.?? Hope that I get the same help like last time..!!
    "Yea though I walk through the valley of the shadow of death... I will fear no evil." -Psalms 23

    K8N Diamond Plus (BIOS v1.2)
    AMD Athlon 64 X2 4400+
    Antec TruControl 550W
    NVidia GeForce 7900GT (NGO v1.8466 BETA)
    OCZ Platinum 2x1GB (2-3-2-5)
    SATA: WD740
    PATA: 2xWD2500, WD1200, NEC DVD/RW

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to write a Property Change Listener in Java?

    Whenever the value of a bound property changes for a bean, property-change events occurs. You should first know properly about the beans, then only you can understand this listener. JavaBeans is a portable, platform-independent component model written in the Java programming language. You can create reuseable, platform-independent components, by using the JavaBeans API. Normally JavaBeans are called as beans. You can change or customize the beans, since they are dynamic in nature. For communication with the other beans, the beans use an events. Beans expose properties so they can be customized at design time.

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: How to write a Property Change Listener in Java?

    You may need the property change listener many times. The following are some conditions where you have to use the property-change listeners :
    1. You need a way to detect when the user has entered a new value after implementing a formatted text field. For listening to changes on the value property, you will have to register a property-change listener on the formatted text field.
    2. You have implemented a dialog. By doing this you can know when a user has clicked one of the dialog's buttons or changed a selection in the dialog.
    3. You can register a property-change listener on the keyboard focus manager to listen to changes to the focusOwner property.

  4. #4
    Join Date
    Mar 2008
    Posts
    672

    Re: How to write a Property Change Listener in Java?

    I have provided you with a sample of the coding that can help you for writing a property-change listener in Java :
    Code:
    KeyboardFocusManager focusManager =
       KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener(new FocusManagerListener());
    ...
    public FocusManagerListener() implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();
            if ("focusOwner".equals(propertyName) {
                ...
            } else if ("focusedWindow".equals(propertyName) {
                ...
            }
        }
        ...
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: How to write a Property Change Listener in Java?

    Registration of a property is very important, otherwise you cannot use that. I have given the coding that shows how to register a property change listener on the value property :
    Code:
    double amount;
    JFormattedTextField amtField;
    ...
    amtField.addPropertyChangeListener("value",
                                          new FormattedTextFieldListener());
    ...
    class FormattedTextFieldListener implements PropertyChangeListener {
        public void propertyChanged(PropertyChangeEvent pe) {
            Object source = pe.getSource();
            if (source == amtField) {
                amt = ((Number)amountField.getValue()).doubleValue();
                ...
            }
        }
    }

Similar Threads

  1. How to write a Mouse Listener in Java?
    By PsYcHo 1 in forum Software Development
    Replies: 4
    Last Post: 13-02-2010, 03:47 AM
  2. How to write a Key Listener in Java?
    By N I C K in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 01:52 AM
  3. How to write a Focus Listener in Java?
    By The Recruiter in forum Software Development
    Replies: 4
    Last Post: 12-02-2010, 07:05 AM
  4. How to write a Change Listener in Java?
    By Samarth in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 06:10 AM
  5. How to write a Caret Listener in Java?
    By Dilbert in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 05:33 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,302,989.37930 seconds with 16 queries