Results 1 to 3 of 3
  1. #1
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Rep Power

    Default Can you catch/suppress events?

    I have a subroutine that updates items in a form, but I don't want it to generate any action events. Is there a way to catch events or suppress event generation in a subroutine? I still want the application to recognize events generated by user input.

    Java Code:
    import java.awt.event.*;
    import javax.swing.*;
    public class MyPanel extends JPanel implements ActionListener {
        private JComboBox boxA;
        private JCheckBox check;
        private MyObject someObject;
        public MyPanel(MyObject anObject) {
            this.boxA = new JComboBox();
            this.check = new JCheckBox();
            this.someObject = anObject;
        // this method I do not want to generate any events
        public void update(String cbData, boolean isCheck) {
        // this method should be able to get events triggered by user
        public void ActionPerformed(ActionEvent ae) {
            // get swing component values and update someObject

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Rep Power

    Post no events generated

    Your code as shown does not generate events where the comment states you do not want events generated.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Rep Power


    It does. As soon as I update the combo box, it generates comboBoxChanged events. But in actionPerformed, I'm updating an object. I don't want to update the object with what I just displayed in the combobox. It's unnecessary cpu cycles.

    Of course, as soon as I submitted this question I thought of a solution. I'll set a flag at the beginning of update, remove the flag at the end of update, and check for the flag in actionPerformed. If the flag exists, then we're in the middle of update. If it doesn't exist, then it's a user event.

Similar Threads

  1. how to catch two exceptions in one catch()?
    By arnab321 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 11:54 AM
  2. Need Help with events
    By Gatts79 in forum AWT / Swing
    Replies: 3
    Last Post: 09-23-2008, 04:18 AM
  3. try catch!?
    By Joe2003 in forum Advanced Java
    Replies: 2
    Last Post: 01-28-2008, 08:51 PM
  4. Try Catch
    By Renegade85 in forum New To Java
    Replies: 4
    Last Post: 12-03-2007, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts