Demonstrates mouse events : Event « SWT JFace Eclipse « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » SWT JFace Eclipse » Event 




Demonstrates mouse events
Demonstrates mouse events


//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner ([email protected])
//Robert Harris ([email protected])

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates mouse events
 */
public class MouseEventExample implements MouseListener, MouseMoveListener,
    MouseTrackListener {

  // The label to hold the messages from mouse events
  Label myLabel = null;

  /**
   * MouseEventExample constructor
   
   @param shell the shell
   */
  public MouseEventExample(Shell shell) {
    myLabel = new Label(shell, SWT.BORDER);
    myLabel.setText("I ain't afraid of any old mouse");
    shell.addMouseListener(this);
    shell.addMouseMoveListener(this);
    shell.addMouseTrackListener(this);
  }

  /**
   * The application entry point
   
   @param args the command line arguments
   */
  public static void main(String[] args) {
    // Create the window
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    shell.setSize(450200);
    shell.setText("Mouse Event Example");

    // Create the listener
    MouseEventExample myMouseEventExample = new MouseEventExample(shell);

    // Display the window
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }

  /**
   * Called when user double-clicks the mouse
   */
  public void mouseDoubleClick(MouseEvent e) {
    myLabel.setText("Double Click " + e.button + " at: " + e.x + "," + e.y);
  }

  /**
   * Called when user clicks the mouse
   */
  public void mouseDown(MouseEvent e) {
    myLabel.setText("Button " + e.button + " Down at: " + e.x + "," + e.y);
  }

  /**
   * Called when user releases the mouse after clicking
   */
  public void mouseUp(MouseEvent e) {
    myLabel.setText("Button " + e.button + " Up at: " + e.x + "," + e.y);
  }

  /**
   * Called when user moves the mouse
   */
  public void mouseMove(MouseEvent e) {
    myLabel.setText("Mouse Move at: " + e.x + "," + e.y);
  }

  /**
   * Called when user enters the shell with the mouse
   */
  public void mouseEnter(MouseEvent e) {
    myLabel.setText("Mouse Enter at: " + e.x + "," + e.y);
  }

  /**
   * Called when user exits the shell with the mouse
   */
  public void mouseExit(MouseEvent e) {
    myLabel.setText("Mouse Exit at: " + e.x + "," + e.y);
  }

  /**
   * Called when user hovers the mouse
   */
  public void mouseHover(MouseEvent e) {
    myLabel.setText("Mouse Hover at: " + e.x + "," + e.y);
  }
}


           
       














Related examples in the same category
1.ModifyEvent: Temperature Converter JFaceModifyEvent: Temperature Converter JFace
2.Mouse Event Listener Mouse Event Listener
3.Utility class for event handling
4.Demonstrates various listenersDemonstrates various listeners
5.Demonstrates ControlListenersDemonstrates ControlListeners
6.SelectionListener and DisposeListenerSelectionListener and DisposeListener
7.Demonstrates FocusListenerDemonstrates FocusListener
8.Demonstrates LineBackgroundListenersDemonstrates LineBackgroundListeners
9.Key Listener Example
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.