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

java.awt.event.InputEvent.BUTTON1_MASK not set properly for event delivered to

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • None
    • 1.1
    • client-libs
    • x86
    • windows_nt

    Description



      Name: sgC58550 Date: 05/14/97


      Click with primary button on mouse,
      Modifier on MouseEvent received by listener in mousePressed, mouseClicked
      does not have BUTTON1_MASK set.

      Here are three files to make an applet/application under 1.1
      which exhibits the bug, and the work-around.

      ////
      //// Begin WindowEngine.java
      /////

      import java.applet.*;
      import java.awt.*;

      public class WindowEngine extends Applet
      {
      //Data members
      MainFrame mainFrame = null; //the window in which the frames will be embedded

      //Initialization methods
      public void init()
      {
      mainFrame = new MainFrame("MainFrame");
      mainFrame.show();
      }

      public static void main(String args[])
      {
      WindowEngine applet = new WindowEngine();
      applet.init();
      }
      }; //class WindowEngine

      ////
      //// End WindowEngine.java
      /////


      ///////
      ////// Begin MainFrame.java
      //////

      import java.applet.*;
      import java.awt.*;
      import java.util.*;

      public class MainFrame extends Frame
      {
      //Data Members
      MainPanel mainPanel;

      //Initialization methods
      public MainFrame(String title)
      {
      super(title);

      reshape(100, 50, 800, 400);

      // create layout
      this.setLayout(new BorderLayout(0, 0));

      // create menu (so we can quit)
      MenuBar menuBar = new MenuBar();
      Menu file = new Menu("File", true);
      menuBar.add(file);
      file.add("Quit");
      this.setMenuBar(menuBar);

      // create main panel for contained items
      // we use this so that mouse coordinates map directly into screen coordinates
      // (corresponding to the origin of mainPanel)
      mainPanel = new MainPanel(this);

      this.add("Center", mainPanel);
      }

      public boolean action(Event e, Object arg)
      {
      if(e.target instanceof MenuItem)
      {
      String label = (String) arg;
      if(label.equals("Quit"))
      {
      System.exit(0);
      }
      }
      return false;
      }

      }; //class MainFrame

      ///////
      ////// end MainFrame.java
      //////

      ///////
      ////// begin MainPanel.java
      //////

      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;

      public class MainPanel extends Panel
          implements MouseListener, MouseMotionListener

      {
      // Data Members
      Frame m_parentFrame;

      // Mouse select info
      int m_x, m_y, m_nWidth, m_nHeight;

      public MainPanel(Frame parentFrame)
      {
      super();

      m_parentFrame = parentFrame;

      // create layout
      this.setLayout(new BorderLayout(0, 0));

      addMouseListener(this);
      addMouseMotionListener(this);
      }

      public void paint(Graphics g)
      {
      super.paint(g);
          }

          protected void studyModifiers(MouseEvent e)
          {
              int Modifiers = e.getModifiers();

              if (( Modifiers & MouseEvent.BUTTON1_MASK) != 0)
              {
                  System.out.println("\tButton1 is down");
              }

              if (( Modifiers & MouseEvent.BUTTON2_MASK) != 0)
              {
                  System.out.println("\tButton2 is down");
              }

              if (( Modifiers & MouseEvent.BUTTON3_MASK) != 0)
              {
                  System.out.println("\tButton3 is down");
              }



          }

          /**
           * Invoked when the mouse has been clicked on a component.
           **/
          public void mouseClicked(MouseEvent e)
          {

              System.out.println("mouseClicked " + e.getClickCount() + " times");
              studyModifiers(e);
          }

          /**
           * Invoked when a mouse button has been pressed on a component.
           **/
          public void mousePressed(MouseEvent e)
          {
              System.out.println("mousePressed");

              if ( (e.getModifiers() & (MouseEvent.BUTTON3_MASK | MouseEvent.BUTTON2_MASK)) == 0)
               {
                  System.out.println("\tWORKAROUND Button 1 is down");
              }

              studyModifiers(e);

          }

          /**
           * Invoked when a mouse button has been released on a component.
           **/
          public void mouseReleased(MouseEvent e)
          {
              System.out.println("mouseReleased");
              studyModifiers(e);

          }

          /**
           * Invoked when the mouse enters a component.
           **/
          public void mouseEntered(MouseEvent e)
          {
              System.out.println("mouseEntered");
              studyModifiers(e);


          }

          /**
           * Invoked when the mouse exits a component.
           **/
          public void mouseExited(MouseEvent e)
          {
              System.out.println("mouseExited");
              studyModifiers(e);

          }


          ///////////////////////////////////////////////////////////////////////////////////
          //// MouseMotionListener
          ///////////////////////////////////////////////////////////////////////////////////

          /**
           * Invoked when a mouse button is pressed on a component and then dragged.
           * Mouse drag events will continue to be delivered to the component where the first originated
           * until the mouse button is released (regardless of whether the mouse position
           * is within the bounds of the component).
           **/
          public void mouseDragged(MouseEvent e)
          {
              // Update the dragging feedback.
              System.out.println(" mouseDragged");
              studyModifiers(e);

          }

          /**
           * Invoked when the mouse button has been moved on a component (with no buttons no down).
           **/
          public void mouseMoved(MouseEvent e)
          {
              System.out.println(" mouseMoved");
              studyModifiers(e);

          }
      } //class MainPanel

      ///
      /// end MainPanel.java
      ///

      company - Corel Corporation
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              sgoodsunw Sheri Good (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: