MouseEvent.MOUSE_RELEASED : MouseEvent « java.awt.event « Java by API

Java by API
1. com.sun.image.codec.jpeg
2. java.applet
3. java.awt
4. java.awt.datatransfer
5. java.awt.dnd
6. java.awt.event
7. java.awt.font
8. java.awt.geom
9. java.awt.im.spi
10. java.awt.image
11. java.awt.print
12. java.beans
13. java.beans.beancontext
14. java.io
15. java.lang
16. java.lang.annotation
17. java.lang.instrument
18. java.lang.management
19. java.lang.ref
20. java.lang.reflect
21. java.math
22. java.net
23. java.nio
24. java.nio.channels
25. java.nio.charset
26. java.rmi.dgc
27. java.rmi.server
28. java.security
29. java.security.cert
30. java.security.spec
31. java.sql
32. java.text
33. java.text.spi
34. java.util
35. java.util.concurrent
36. java.util.concurrent.atomic
37. java.util.concurrent.locks
38. java.util.jar
39. java.util.logging
40. java.util.prefs
41. java.util.regex
42. java.util.spi
43. java.util.zip
44. javax.accessibility
45. javax.activation
46. javax.annotation.security
47. javax.comm
48. javax.crypto
49. javax.crypto.spec
50. javax.ejb
51. javax.imageio
52. javax.imageio.event
53. javax.jws
54. javax.mail
55. javax.mail.internet
56. javax.media.jai
57. javax.microedition.io
58. javax.microedition.lcdui
59. javax.microedition.media
60. javax.microedition.media.control
61. javax.microedition.midlet
62. javax.microedition.pim
63. javax.microedition.rms
64. javax.naming
65. javax.naming.directory
66. javax.naming.event
67. javax.naming.ldap
68. javax.naming.spi
69. javax.net
70. javax.net.ssl
71. javax.persistence
72. javax.print
73. javax.print.attribute
74. javax.print.attribute.standard
75. javax.print.event
76. javax.script
77. javax.servlet
78. javax.servlet.http
79. javax.sound.midi
80. javax.sound.sampled
81. javax.sql
82. javax.sql.rowset
83. javax.swing
84. javax.swing.border
85. javax.swing.colorchooser
86. javax.swing.event
87. javax.swing.filechooser
88. javax.swing.plaf.basic
89. javax.swing.plaf.metal
90. javax.swing.plaf.synth
91. javax.swing.table
92. javax.swing.text
93. javax.swing.text.html
94. javax.swing.text.html.parser
95. javax.swing.text.rtf
96. javax.swing.tree
97. javax.swing.undo
98. javax.tools
99. javax.transaction
100. javax.xml
101. javax.xml.bind
102. javax.xml.bind.annotation
103. javax.xml.crypto.dsig
104. javax.xml.crypto.dsig.keyinfo
105. javax.xml.namespace
106. javax.xml.parsers
107. javax.xml.soap
108. javax.xml.stream
109. javax.xml.stream.events
110. javax.xml.transform
111. javax.xml.transform.dom
112. javax.xml.transform.stream
113. javax.xml.validation
114. javax.xml.ws
115. javax.xml.xpath
116. junit.extensions
117. junit.framework
118. junit.textui
119. org.apache.commons.lang
120. org.apache.commons.lang.builder
121. org.apache.commons.lang.exception
122. org.apache.commons.lang.time
123. org.apache.commons.logging
124. org.apache.commons.math
125. org.eclipse.jface.action
126. org.eclipse.jface.dialogs
127. org.eclipse.jface.operation
128. org.eclipse.jface.viewers
129. org.eclipse.jface.window
130. org.eclipse.jface.wizard
131. org.eclipse.swt
132. org.eclipse.swt.browser
133. org.eclipse.swt.custom
134. org.eclipse.swt.dnd
135. org.eclipse.swt.events
136. org.eclipse.swt.graphics
137. org.eclipse.swt.layout
138. org.eclipse.swt.ole.win32
139. org.eclipse.swt.printing
140. org.eclipse.swt.program
141. org.eclipse.swt.widgets
142. org.junit
143. org.w3c.dom
144. org.xml.sax
145. org.xml.sax.helpers
146. sun.audio
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java by API » java.awt.event » MouseEvent 
MouseEvent.MOUSE_RELEASED
  


/*
 * Copyright (c) 2000 David Flanagan.  All rights reserved.
 * This code is from the book Java Examples in a Nutshell, 2nd Edition.
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.
 * You may study, use, and modify it for any non-commercial purpose.
 * You may distribute it non-commercially as long as you retain this notice.
 * For a commercial use license, or to purchase the book (recommended),
 * visit http://www.davidflanagan.com/javaexamples2.
 */

import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;

/** A program that displays all the event that occur in its window */
public class EventTestPane extends JPanel {
  /** The constructor: register the event types we are interested in */
  public EventTestPane() {
    // We're interested in all types of events
    this.enableEvents(AWTEvent.MOUSE_EVENT_MASK
        | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.KEY_EVENT_MASK
        | AWTEvent.FOCUS_EVENT_MASK | AWTEvent.COMPONENT_EVENT_MASK
        | AWTEvent.WINDOW_EVENT_MASK);
    this.setPreferredSize(new Dimension(500400));
  }

  /**
   * Display mouse events that don't involve mouse motion. The mousemods()
   * method prints modifiers, and is defined below. The other methods return
   * additional information about the mouse event. showLine() displays a line
   * of text in the window. It is defined at the end of this class, along with
   * the paintComponent() method.
   */
  public void processMouseEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
      type = "MOUSE_PRESSED";
      break;
    case MouseEvent.MOUSE_RELEASED:
      type = "MOUSE_RELEASED";
      break;
    case MouseEvent.MOUSE_CLICKED:
      type = "MOUSE_CLICKED";
      break;
    case MouseEvent.MOUSE_ENTERED:
      type = "MOUSE_ENTERED";
      break;
    case MouseEvent.MOUSE_EXITED:
      type = "MOUSE_EXITED";
      break;
    }
    showLine(mousemods(e+ type + ": [" + e.getX() "," + e.getY() "] "
        "num clicks = " + e.getClickCount()
        (e.isPopupTrigger() "; is popup trigger" ""));

    // When the mouse enters the component, request keyboard focus so
    // we can receive and respond to keyboard events
    if (e.getID() == MouseEvent.MOUSE_ENTERED)
      requestFocus();
  }

  /**
   * Display mouse moved and dragged mouse event. Note that MouseEvent is the
   * only event type that has two methods, two EventListener interfaces and
   * two adapter classes to handle two distinct categories of events. Also, as
   * seen in init(), mouse motion events must be requested separately from
   * other mouse event types.
   */
  public void processMouseMotionEvent(MouseEvent e) {
    String type = null;
    switch (e.getID()) {
    case MouseEvent.MOUSE_MOVED:
      type = "MOUSE_MOVED";
      break;
    case MouseEvent.MOUSE_DRAGGED:
      type = "MOUSE_DRAGGED";
      break;
    }
    showLine(mousemods(e+ type + ": [" + e.getX() "," + e.getY() "] "
        "num clicks = " + e.getClickCount()
        (e.isPopupTrigger() "; is popup trigger" ""));
  }

  /**
   * Return a string representation of the modifiers for a MouseEvent. Note
   * that the methods called here are inherited from InputEvent.
   */
  protected String mousemods(MouseEvent e) {
    int mods = e.getModifiers();
    String s = "";
    if (e.isShiftDown())
      s += "Shift ";
    if (e.isControlDown())
      s += "Ctrl ";
    if ((mods & InputEvent.BUTTON1_MASK!= 0)
      s += "Button 1 ";
    if ((mods & InputEvent.BUTTON2_MASK!= 0)
      s += "Button 2 ";
    if ((mods & InputEvent.BUTTON3_MASK!= 0)
      s += "Button 3 ";
    return s;
  }

  /**
   * Display keyboard events.
   
   * Note that there are three distinct types of key events, and that key
   * events are reported by key code and/or Unicode character. KEY_PRESSED and
   * KEY_RELEASED events are generated for all key strokes. KEY_TYPED events
   * are only generated when a key stroke produces a Unicode character; these
   * events do not report a key code. If isActionKey() returns true, then the
   * key event reports only a key code, because the key that was pressed or
   * released (such as a function key) has no corresponding Unicode character.
   * Key codes can be interpreted by using the many VK_ constants defined by
   * the KeyEvent class, or they can be converted to strings using the static
   * getKeyText() method as we do here.
   */
  public void processKeyEvent(KeyEvent e) {
    String eventtype, modifiers, code, character;
    switch (e.getID()) {
    case KeyEvent.KEY_PRESSED:
      eventtype = "KEY_PRESSED";
      break;
    case KeyEvent.KEY_RELEASED:
      eventtype = "KEY_RELEASED";
      break;
    case KeyEvent.KEY_TYPED:
      eventtype = "KEY_TYPED";
      break;
    default:
      eventtype = "UNKNOWN";
    }

    // Convert the list of modifier keys to a string
    modifiers = KeyEvent.getKeyModifiersText(e.getModifiers());

    // Get string and numeric versions of the key code, if any.
    if (e.getID() == KeyEvent.KEY_TYPED)
      code = "";
    else
      code = "Code=" + KeyEvent.getKeyText(e.getKeyCode()) " ("
          + e.getKeyCode() ")";

    // Get string and numeric versions of the Unicode character, if any.
    if (e.isActionKey())
      character = "";
    else
      character = "Character=" + e.getKeyChar() " (Unicode="
          ((inte.getKeyChar()) ")";

    // Display it all.
    showLine(eventtype + ": " + modifiers + " " + code + " " + character);
  }

  /**
   * Display keyboard focus events. Focus can be permanently gained or lost,
   * or temporarily transferred to or from a component.
   */
  public void processFocusEvent(FocusEvent e) {
    if (e.getID() == FocusEvent.FOCUS_GAINED)
      showLine("FOCUS_GAINED" (e.isTemporary() " (temporary)" ""));
    else
      showLine("FOCUS_LOST" (e.isTemporary() " (temporary)" ""));
  }

  /** Display Component events. */
  public void processComponentEvent(ComponentEvent e) {
    switch (e.getID()) {
    case ComponentEvent.COMPONENT_MOVED:
      showLine("COMPONENT_MOVED");
      break;
    case ComponentEvent.COMPONENT_RESIZED:
      showLine("COMPONENT_RESIZED");
      break;
    case ComponentEvent.COMPONENT_HIDDEN:
      showLine("COMPONENT_HIDDEN");
      break;
    case ComponentEvent.COMPONENT_SHOWN:
      showLine("COMPONENT_SHOWN");
      break;
    }
  }

  /** Display Window events. Note the special handling of WINDOW_CLOSING */
  public void processWindowEvent(WindowEvent e) {
    switch (e.getID()) {
    case WindowEvent.WINDOW_OPENED:
      showLine("WINDOW_OPENED");
      break;
    case WindowEvent.WINDOW_CLOSED:
      showLine("WINDOW_CLOSED");
      break;
    case WindowEvent.WINDOW_CLOSING:
      showLine("WINDOW_CLOSING");
      break;
    case WindowEvent.WINDOW_ICONIFIED:
      showLine("WINDOW_ICONIFIED");
      break;
    case WindowEvent.WINDOW_DEICONIFIED:
      showLine("WINDOW_DEICONIFIED");
      break;
    case WindowEvent.WINDOW_ACTIVATED:
      showLine("WINDOW_ACTIVATED");
      break;
    case WindowEvent.WINDOW_DEACTIVATED:
      showLine("WINDOW_DEACTIVATED");
      break;
    }

    // If the user requested a window close, quit the program.
    // But first display a message, force it to be visible, and make
    // sure the user has time to read it.
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      showLine("WINDOW_CLOSING event received.");
      showLine("Application will exit in 5 seconds");
      // Force the updates to appear now.
      update(this.getGraphics());
      // Wait five seconds
      try {
        Thread.sleep(5000);
      catch (InterruptedException ie) {
        ;
      }
      // Exit now
      System.exit(0);
    }
  }

  /** The list of lines to display in the window */
  protected Vector lines = new Vector();

  /** Add a new line to the list of lines, and request redisplay */
  protected void showLine(String s) {
    if (lines.size() == 20)
      lines.removeElementAt(0);
    lines.addElement(s);
    repaint();
  }

  /** This method repaints the text in the window */
  public void paintComponent(Graphics g) {
    for (int i = 0; i < lines.size(); i++)
      g.drawString((Stringlines.elementAt(i)20, i * 16 50);
  }

  public boolean isOpaque() {
    return false;
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    frame.getContentPane().add(new EventTestPane(), BorderLayout.CENTER);
    // Finally, set the size of the main window, and pop it up.
    frame.setSize(600400);
    frame.setVisible(true);
  }
}

   
    
  
Related examples in the same category
1. MouseEvent.MOUSE_CLICKED
2. MouseEvent.MOUSE_ENTERED
3. MouseEvent.MOUSE_EXITED
4. MouseEvent.MOUSE_PRESSED
5. MouseEvent: getClickCount()
6. MouseEvent: getComponent()
7. MouseEvent: getModifiers()
8. MouseEvent: getX()
9. MouseEvent.getY()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.