《Java 编程技巧1001条》第415条:使用keyDown方法
2017-12-25 08:56
471 查看
《Java 编程技巧1001条》第11章 事件驱动
第415条 使用keyDown方法
415 Using the keyDown Method
415 使用键盘事件
As you have learned, Java provides convenience methods that make capturing
mouse events easy. For example, when the user holds down the mouse button,
Java will call the mouseDown method. Similarly, when the user presses a
keyboard key, Java will call the keyDown convenience method. The arguments
to the keyDown method are the Event object and a key code. The following
program, keyDownApplet.java, demonstrates how to capture key strokes and
display them within the status window:
正如你所了解的那样,Java提供的convenience方法使得事件的捕捉变得容易. 例如,
用户按下mouse键时,Java将调用mouseDown方法. 类似地,当用户按键盘上的键时,
Java将调用keyDown方法. keyDown方法的自变量是Event对象和所按键的代码. 以下
keyDownApplet.java程序说明了捕捉按键并将它们显示在状态窗口中:
import java.applet.*;
import java.awt.*;
public class keyDownApplet extends Applet {
public boolean keyDown(Event evt, int code)
{
System.out.println("keyDown:" + (char)code);
return(true);
}
}
415 Using the keyDown Method
415 使用键盘事件
As you have learned, Java provides convenience methods that make capturing
mouse events easy. For example, when the user holds down the mouse button,
Java will call the mouseDown method. Similarly, when the user presses a
keyboard key, Java will call the keyDown convenience method. The arguments
to the keyDown method are the Event object and a key code. The following
program, keyDownApplet.java, demonstrates how to capture key strokes and
display them within the status window:
正如你所了解的那样,Java提供的convenience方法使得事件的捕捉变得容易. 例如,
用户按下mouse键时,Java将调用mouseDown方法. 类似地,当用户按键盘上的键时,
Java将调用keyDown方法. keyDown方法的自变量是Event对象和所按键的代码. 以下
keyDownApplet.java程序说明了捕捉按键并将它们显示在状态窗口中:
import java.applet.*;
import java.awt.*;
public class keyDownApplet extends Applet {
public boolean keyDown(Event evt, int code)
{
System.out.println("keyDown:" + (char)code);
return(true);
}
}
相关文章推荐
- 《Java 编程技巧1001条》 第406条: 使用mouseUp方法
- 《Java 编程技巧1001条》 第405条: 使用mouseDoun方法
- 《Java 编程技巧1001条》第416条:使用keyUp方法
- 《Java 编程技巧1001条》 第407条:使用mouseDrag方法,
- 《Java 编程技巧1001条》 第408条: 使用mouseMove方法,
- 《Java 编程技巧1001条》第409...条: 使用crickCount方法,
- 《Java 编程技巧1001条》 第420...条: 使用handle event 方法
- 《Java 编程技巧1001条》 第404条: 了解实用方法
- 绝对使用JavaMyEclipse使用方法,不会让你失望....提高编程技巧和速度
- 《Java 编程技巧1001条》 第399条:对原始类型数组使用数组复制
- 《Java 编程技巧1001条》 第397+398条:了解和使用快速排序
- 绝对使用JavaEclipse使用方法,不会让你失望....提高编程技巧和速度
- 《Java 编程技巧1001条》 第395与396条 :了解和使用冒泡排序
- 《Java 编程技巧1001条》第410条: 检测双击的另一种方法
- 《Java 编程技巧1001条》 第393条: 使用2分查找
- 《Java 编程技巧1001条》第418条:检测多个修饰键的另一方法
- 《Java 编程技巧1001条》 第400条: 使用数组复制
- 《Java 编程技巧1001条》第413条:使用mouseEnter 和 mouseExit
- java.sql.resultset方法与使用技巧
- java多线程编程之使用Synchronized关键字同步类方法