Java by API/org.eclipse.swt.events/MouseEvent

Материал из Java эксперт
Перейти к: навигация, поиск

MouseEvent: button

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
  public static void main(String[] a) {
    Display d = new Display();
    final Shell s = new Shell(d);
    s.setSize(250, 200);
    s.setText("A MouseListener Example");
    s.open();
    s.addMouseListener(new MouseListener() {
      public void mouseDown(MouseEvent e) {
        System.out.println("Mouse Button Down at:" + e.x + " " + e.y);
      }
      public void mouseUp(MouseEvent e) {
        System.out.println("Mouse Button up at:" + e.x + " " + e.y);
        System.out.println(e.button);
        
      }
      public void mouseDoubleClick(MouseEvent e) {
        System.out.println("Mouse Double Clicked at:" + e.x + " " + e.y);
      }
    });
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }
}





MouseEvent: x

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
  public static void main(String[] a) {
    Display d = new Display();
    final Shell s = new Shell(d);
    s.setSize(250, 200);
    s.setText("A MouseListener Example");
    s.open();
    s.addMouseListener(new MouseListener() {
      public void mouseDown(MouseEvent e) {
        System.out.println("Mouse Button Down at:" + e.x + " " + e.y);
      }
      public void mouseUp(MouseEvent e) {
        System.out.println("Mouse Button up at:" + e.x + " " + e.y);
        System.out.println(e.button);
        
      }
      public void mouseDoubleClick(MouseEvent e) {
        System.out.println("Mouse Double Clicked at:" + e.x + " " + e.y);
      }
    });
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }
}





MouseEvent: y

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
  public static void main(String[] a) {
    Display d = new Display();
    final Shell s = new Shell(d);
    s.setSize(250, 200);
    s.setText("A MouseListener Example");
    s.open();
    s.addMouseListener(new MouseListener() {
      public void mouseDown(MouseEvent e) {
        System.out.println("Mouse Button Down at:" + e.x + " " + e.y);
      }
      public void mouseUp(MouseEvent e) {
        System.out.println("Mouse Button up at:" + e.x + " " + e.y);
        System.out.println(e.button);
        
      }
      public void mouseDoubleClick(MouseEvent e) {
        System.out.println("Mouse Double Clicked at:" + e.x + " " + e.y);
      }
    });
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }
}