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

MouseEvents delivered to wrong component freeze entire desktop

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: joT67522 Date: 01/06/98


      import java.awt.*;
      import java.awt.event.*;

      public class MyFrame extends Frame implements WindowListener,ItemListener
      {
          class Field extends TextField
          {
              boolean focus = false;

              public Field(int length)
              {
                  super(length);
                  addMouseListener(new MouseAdapter()
                  {
                      public void mouseClicked(MouseEvent e)
                      {
                          e.consume();
                          System.out.println("Field Mouse clicked");
                      }

                      public void mousePressed(MouseEvent e)
                      {
                          e.consume();
                          System.out.println("Field Mouse pressed");
                      }

                      public void mouseReleased(MouseEvent e)
                      {
                          // ATTENTION e.consume();
                          System.out.println("Field Mouse released");
                      }
                  });
                  addMouseMotionListener(new MouseMotionAdapter()
                  {
                      public void mouseDragged(MouseEvent e)
                      {
                          e.consume();
                          System.out.println("Field Mouse dragged");
                      }
                      public void mouseMoved(MouseEvent e)
                      {
                          e.consume();
                          System.out.println("Field Mouse moved");
                      }
                  });
              }

              public boolean isFocusTraversable()
              {
                  return focus;
              }

              public void setFocusTraversable(boolean flag)
              {
                  focus = flag;
              }
          }

              Choice choice;

              public MyFrame() {
                      super();
                      addWindowListener(this);
                      choice = new Choice();
                      choice.add("item 1");
                      choice.add("item 2");
                      choice.add("item 3");
                      //choice.addFocusListener(this);
                      choice.addItemListener(this);
                      add("Center",choice);
                      add("East", new Field(10));
              }

              public void itemStateChanged(ItemEvent e)
              {
                      System.out.println("item event");
              }

              public void windowOpened(WindowEvent e){ }

              public void windowClosing(WindowEvent e){
                      dispose();
              }
              public void windowClosed(WindowEvent e){ }
              public void windowIconified(WindowEvent e){ }
              public void windowDeiconified(WindowEvent e){ }
              public void windowActivated(WindowEvent e){ }
              public void windowDeactivated(WindowEvent e){ }

              public static void main(String [] args) {
                      MyFrame f = new MyFrame();
                      f.setSize(200,100);
                      f.setVisible(true);
              }
      }


      Run the followin code.
      Notice that TextField intercepts all of its mouse venets
      and consumes them - desired behavior.
      First compile and run with line in function mouseReleased that
      is labeled ATTENTION commented out.
      Press mouse over Choice and hold it down. While pressed,
      move the mouse out of the Choice and onto the Field.
      Release mouse button, you will see output message that Field
      got mouseReleased event even though the target of this
      event should be Choice not Field. In any case, once
      you release the mouse button, Choice's pull down menu
      is rolled back as if everything was good.
      Now compile an run with line in function mouseReleased
      that is labeled ATTENTION commented in so that e.consume()
      will be executed. Repeat the same steps from above.
      Once you release the mouse button over the text field
      ENTIRE Desktop FREEZES, DEADLOCKS, whatever you call it!!!!!

      And this is all because the mouseReleased event should have never been
      delivered to the Text Field in the first place.

      I am running Solaris 2.5 on SPARC station 5 with CDE (Common
      Desktop Environment) window manager.
      (Review ID: 22772)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              johsunw Joon Oh (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: