Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4186680

MenuItem.enableEvents(long) works wrong

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.8
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Backports

        Description



        Name: dsC58869 Date: 11/03/98



        The method MenuItem.enableEvents(long eventsToEnable) does not allow
        subclasses of MenuItem to have the specified event types delivered
        to processEvent method regardless of whether a listener is registered.

        ==== Here is the test demonstrating the bug ====
        import java.awt.*;
        import java.awt.event.*;

        public class TestMenuItem extends MenuItem{

            public TestMenuItem (String label) {
        super (label);
            }

            boolean processed = false;

            public void processEvent(AWTEvent e) {
        processed = true;
            }

            public static void main (String args[]) {
        String item = "Item";
        TestMenuItem mi = new TestMenuItem(item);

        /* part 1: enable action event */
        mi.enableEvents(AWTEvent.ACTION_EVENT_MASK);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
        new ActionEvent(mi, ActionEvent.ACTION_PERFORMED, "Event"));
        try { Thread.sleep(10000); } catch (Exception e) {
        e.printStackTrace();
        }
        if (mi.processed) {
        System.out.println("OKAY: processEvent invoked");
        } else {
        System.out.println("FAILED: processEvent not invoked");
        }

        /* part 2: add and remove listener;
        action event enabled */
        MyActionListener myal = new MyActionListener();
        mi.addActionListener(myal);
        mi.removeActionListener(myal);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
        new ActionEvent(mi, ActionEvent.ACTION_PERFORMED, "Event"));
        try { Thread.sleep(10000); } catch (Exception e) {
        e.printStackTrace();
        }
        if (mi.processed) {
        System.out.println("OKAY: processEvent invoked");
        } else {
        System.out.println("FAILED: processEvent not invoked");
        }
        System.exit(0);
            }
        }

        class MyActionListener implements ActionListener {
          public void actionPerformed(ActionEvent e){}
        }


        ==== Here is the output of the test ====
        %java -fullversion
        java full version "JDK-1.2fcs-P"
        %java TestMenuItem
        FAILED: processEvent not invoked
        OKAY: processEvent invoked

        ======================================================================
         Justification:
        The method should work properly

        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                xdengsunw Xianfa Deng (Inactive)
                Reporter:
                dsilaev Dmitri Silaev
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: