mouselistener.html
来自「jsf、swing的官方指南」· HTML 代码 · 共 874 行 · 第 1/3 页
HTML
874 行
<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/MouseEvent.html#isPopupTrigger()">boolean isPopupTrigger()</a></td><td>Return <code>true</code> if the mouse event should cause a popup menu to appear. Because popup triggers are platform dependent, if your program uses popup menus, you should call <code>isPopupTrigger</code> for all mouse-pressed and mouse-released events fired by components over which the popup can appear. See <a href="../components/menu.html#popup">Bringing Up a Popup Menu</a> for more information about popup menus.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/MouseEvent.html#getMouseModifiersText(int)">String getMouseModifiersText(int)</a></td><td>Return a <code>String</code> describing the modifier keys and mouse buttons that were active during the event, such as "Shift", or "Ctrl+Shift". These strings can be localized using the awt.properties file. Introduced in release 1.4.</td></tr></table><p align=center><a name="inputevent">The InputEvent Class</a><p>The <code>MouseEvent</code> class inherits many usefulmethods from <a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html">InputEvent</a> and a couple handy methods from the<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/ComponentEvent.html"><code>ComponentEvent</code></a> and<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/AWTEvent.html"><code>AWTEvent</code></a> classes.<table border=1><tr><th align=left>Method</th><th align=left>Purpose</th></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/AWTEvent.html#getID()">int getID()</a><br>(<em>in <code>java.awt.AWTEvent</code></em>)</td><td>Return the event type.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/ComponentEvent.html#getComponent()">Component getComponent()</a><br>(<em>in <code>ComponentEvent</code></em>)</td><td> Return the component that fired the event. You can use this method instead of the <code>getSource</code> method.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html#getWhen()">int getWhen()</a></td><td>Return the timestamp of when this event occurred. The higher the timestamp, the more recently the event occurred.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html#isAltDown()">boolean isAltDown()</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html#isControlDown()">boolean isControlDown()</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html#isMetaDown()">boolean isMetaDown()</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html#isShiftDown()">boolean isShiftDown()</a><br></td><td>Return the state of individual modifier keys at the time the event was fired.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html#getModifiers()">int getModifiers()</a></td><td>Return the state of all the modifier keys and mouse buttons when the event was fired. You can use this method to determine which mouse button was pressed (or newly released) when a mouse event was fired. The <code>InputEvent</code> class defines these constants for use with the <code>getModifiers</code> method: <code>ALT_MASK</code>, <code>BUTTON1_MASK</code>, <code>BUTTON2_MASK</code>, <code>BUTTON3_MASK</code>, <code>CTRL_MASK</code>, <code>META_MASK</code>, and <code>SHIFT_MASK</code>. For example, the following expression is true if the right button was pressed:<blockquote><pre>(mouseEvent.getModifiers() & InputEvent.BUTTON3_MASK)== InputEvent.BUTTON3_MASK</pre></blockquote></td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html#getModifiersEx()">int getModifiersEx()</a></td><td>Return the extended modifier mask for this event. Extended modifiers represent the state of all modal keys, such as ALT, CTRL, META, and the mouse buttons just after the event occurred. You can check the status of the modifiers using one of the following predefined bitmasks: <code>SHIFT_DOWN_MASK</code>, <code>CTRL_DOWN_MASK</code>, <code>META_DOWN_MASK</code>, <code>ALT_DOWN_MASK</code>, <code>BUTTON1_DOWN_MASK</code>, <code>BUTTON2_DOWN_MASK</code>, <code>BUTTON3_DOWN_MASK</code>, or <code>ALT_GRAPH_DOWN_MASK</code>. For example, to check that button 1 is down, but that buttons 2 and 3 are up, you would use the following code snippet:<blockquote><pre>if (event.getModifiersEx() & (BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK | BUTTON3_DOWN_MASK) == BUTTON1_DOWN_MASK) { ...}</pre></blockquote> Introduced in release 1.4.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/awt/event/InputEvent.html#getModifiersExText(int)">int getModifiersExText(int)</a></td><td>Return a string describing the extended modifier keys and mouse buttons, such as "Shift", "Button1", or "Ctrl+Shift". These strings can be localized by changing the awt.properties file. Introduced in release 1.4.</td></tr></table><p align=center><a name="swingutilities">The SwingUtilities Class</a><p>The <a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html">SwingUtilities</a> class contains convenience methods for determining whether a particular mouse button has been pressed.<table border=1><tr><th align=left>Method</th><th align=left>Purpose</th></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#isLeftMouseButton(java.awt.event.MouseEvent)">boolean isLeftMouseButton(MouseEvent)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#isMiddleMouseButton(java.awt.event.MouseEvent)">boolean isMiddleMouseButton(MouseEvent)</a><br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#isRightMouseButton(java.awt.event.MouseEvent)">boolean isRightMouseButton(MouseEvent)</a></td><td>Return <code>true</code> if the passed-in event specifies the left, middle, or right mouse button, respectively. </td></tr></table></blockquote><a name="eg"><h3>Examples that Use Mouse Listeners</h3></a><blockquote>The following table lists theexamples that use mouse listeners. <p> <table><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes </th></tr><tr valign=top><td><a href="examples/index.html#MouseEventDemo"><code>MouseEventDemo</code></a></td><td> This section</td><td> Reports all mouse events that occur within a blank panel to demonstrate the circumstances under which mouse events are fired.</td></tr><tr valign=top><td><a href="../painting/examples/index.html#CoordinatesDemo"><code>CoordinatesDemo</code></a></td><td><a class="TutorialLink" target="_top" href="../painting/concepts2.html">Introduction to Painting Concepts</a></td><td> Draws a small dot where the user clicks the mouse. Also reports the <em>x</em>, <em>y</em> location of the cursor and of the most recent mouse click.</td></tr><tr valign=top><td><a href="../painting/examples/index.html#SelectionDemo"><code>SelectionDemo</code></a></td><td><a class="TutorialLink" target="_top" href="../painting/concepts2.html">Introduction to Painting Concepts</a></td><td> Lets the user drag a rectangle to select a portion of an image. Uses a subclass of <code>MouseInputAdapter</code> to listen to both mouse events and mouse-motion events. </td></tr><tr valign=top><td><a href="../components/examples/index.html#GlassPaneDemo"><code>GlassPaneDemo</code></a></td><td><a class="TutorialLink" target="_top" href="../components/rootpane.html">How to Use Root Panes</a></td><td> Uses a subclass of <code>MouseInputAdapter</code> to listen to mouse events and mouse-motion events on the root pane's glass pane. Redispatches the events to underlying components.</td></tr><tr valign=top><td><a href="../components/examples/index.html#TableSorterDemo"><code>TableSorter</code></a></td><td><a class="TutorialLink" target="_top" href="../components/table.html">How to Use Tables</a></td><td> Listens to mouse events on a table header. Sorts data in the selected column.</td></tr><tr valign=top><td><a href="../components/examples/index.html#PopupMenuDemo"><code>PopupMenuDemo</code></a></td><td> <a class="TutorialLink" target="_top" href="../components/menu.html">How to Use Menus</a></td><td> Displays a popup menu in response to mouse clicks.</td></tr><tr valign=top><td><a href="../misc/examples/index.html#TrackFocusDemo"><code>TrackFocusDemo</code></a></td><td><a class="TutorialLink" target="_top" href="../misc/focus.html">How to Use the Focus Subsystem</a></td><td> The custom component, <code>Picture</code>, implements a mouse listener that requests the focus when a user clicks on the component.</td></tr></table> </blockquote> <div class=NavBit> <a target=_top href=listselectionlistener.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=mousemotionlistener.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Write a List Selection Listener <br><b>Next page:</b> How to Write a Mouse-Motion Listener </div> </body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?