《Java 编程技巧1001条》第418条:检测多个修饰键的另一方法
2017-12-25 09:14
447 查看
《Java 编程技巧1001条》第11章 事件驱动 第418条 检测多个修饰键的另一方法
418 An Alternative Way to Detect Keyboard Modifier Keys
418 检测键盘变动键的另一种方法
In the previous tip, you learned how to detect keyboard modifier keys by examining the Event class modifiers variable. An alternative way to check for modifier keys is to use the methods built into the Event class: controlDown, metaDown, or shiftDown. You can use these methods instead of performing a bitwise AND operation of the modifier constants with the modifiers variable. The following program, altModifierKey.java, demonstrates how to check for modifier keys using the built-in Event class methods:在以上的TIP中,你已知道了怎样利用查看事件类modifier变量的办法来检测键盘的修饰键. 检测修饰键的另一中办法是在Event类中建立的controlDown, metaDown, 或shiftDown三种方法. 你可使用这些方法来代替odifiers变量和modifiers常量之间的按位乘操作. 以下的程序altModifierKey.java说明怎样利用内建的Evenr类方法,来检测修饰键:
import java.applet.*;
import java.awt.*;
public class altModifierKey extends Applet {
public void init()
{
resize(400, 300);
}
public boolean keyDown(Event evt, int key)
{
if (evt.controlDown() && evt.shiftDown())
System.out.println("SHIFT and CTRL pressed");
return(true);
}
}
相关文章推荐
- 《Java 编程技巧1001条》第417条: 检测多个修饰键
- 《Java 编程技巧1001条》第410条: 检测双击的另一种方法
- 《Java 编程技巧1001条》 第411条: 检测鼠标单击修饰键,
- 《Java 编程技巧1001条》第409...条: 使用crickCount方法,
- 《Java 编程技巧1001条》 第408条: 使用mouseMove方法,
- 《Java 编程技巧1001条》 第420...条: 使用handle event 方法
- 《Java 编程技巧1001条》第419条:检测专用键
- 《Java 编程技巧1001条》 第405条: 使用mouseDoun方法
- 《Java 编程技巧1001条》 第404条: 了解实用方法
- 《Java 编程技巧1001条》第415条:使用keyDown方法
- 《Java 编程技巧1001条》 第423条: 检测窗口何时已图标化(Iconified)
- 《Java 编程技巧1001条》 第407条:使用mouseDrag方法,
- 《Java 编程技巧1001条》第416条:使用keyUp方法
- 《Java 编程技巧1001条》 第406条: 使用mouseUp方法
- 《Java 编程技巧1001条》 第403条: 了解事件类
- 《Java 编程技巧1001条》 第397+398条:了解和使用快速排序
- 《Java 编程技巧1001条》第402-406条: 了解事件驱动程序,
- 《Java 编程技巧1001条》 第387条: 建立多维数组
- 《Java 编程技巧1001条》第401条:数组中存不同对象
- 《Java 编程技巧1001条》 第388条: 遍历多维数组