當前位置: 首頁>>代碼示例>>Java>>正文


Java InputEvent.getMaskForButton方法代碼示例

本文整理匯總了Java中java.awt.event.InputEvent.getMaskForButton方法的典型用法代碼示例。如果您正苦於以下問題:Java InputEvent.getMaskForButton方法的具體用法?Java InputEvent.getMaskForButton怎麽用?Java InputEvent.getMaskForButton使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.event.InputEvent的用法示例。


在下文中一共展示了InputEvent.getMaskForButton方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initLegalButtonMask

import java.awt.event.InputEvent; //導入方法依賴的package包/類
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:Robot.java

示例2: initLegalButtonMask

import java.awt.event.InputEvent; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:Robot.java

示例3: mouseDragged

import java.awt.event.InputEvent; //導入方法依賴的package包/類
@Override
public final void mouseDragged(final MouseEvent e) {
	for (int b = 0; b < NUM_BUTTONS; b++) {
		if (startPoints[b] != null
				&& (e.getModifiersEx() & InputEvent.getMaskForButton(b + 1)) != 0
				&& startPoints[b].distanceSq(e.getLocationOnScreen()) > CLICK_SENSITIVITY_SQ) {
			startPoints[b] = null;
			FixedMouseAdapter.this.mouseDragStarted(e);
		}
	}
	FixedMouseAdapter.this.mouseDragged(e);
}
 
開發者ID:Njol,項目名稱:Motunautr,代碼行數:13,代碼來源:FixedMouseAdapter.java

示例4: main

import java.awt.event.InputEvent; //導入方法依賴的package包/類
public static void main(String []s){
    System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons());
    CheckGetMaskForButton f = new CheckGetMaskForButton();
    int [] buttonMasksViaAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        buttonMasksViaAPI[i] = InputEvent.getMaskForButton(i+1);
        System.out.println("Test (API): "+ buttonMasksViaAPI[i]);
    }

    //get same array via reflection
    Object obj = AccessController.doPrivileged(
            new PrivilegedAction() {
        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method  = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[])null);
                }
            }catch (Exception e){
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });

    if (obj == null){
        throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);
    }

    int [] buttonDownMasksViaReflection = new int [Array.getLength(obj)];
    //check that length of API array greater or equals then Reflect array.
    if (Array.getLength(obj) < buttonMasksViaAPI.length){
        throw new RuntimeException("Test failed. The length of API array greater or equals then the length of  Reflect array.");
    }

    //Check that the values obtained via reflection from InputEvent.BUTTON_DOWN_MASK are the
    // same as for standard API.
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
        System.out.println("Test (Reflection): "+ Array.getInt(obj, i));
        if (buttonMasksViaAPI[i] != Array.getInt(obj, i)){
            throw new RuntimeException("Test failed. Values of InputEvent array are different for API and Reflection invocations");
        }
    }
    System.out.println("Test passed.");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:48,代碼來源:CheckGetMaskForButton.java


注:本文中的java.awt.event.InputEvent.getMaskForButton方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。