Java Reference
In-Depth Information
and “typed,” respectively. Key presses and releases are low level events that
depend on the keyboard and platform in use. Key “typed” events are higher level
events that occur when a typing action is complete and are the preferred way to
find out about character input. Combinations of keys can be detected by testing
the key code. The KeyEvent class provides the codes as constants. For exam-
ple, this code snippet tests if the left arrow and shift keys were simultaneously
pressed:
public void keyPressed (KeyEvent e) {
int keyCode = e.getKeyCode ();
if (keyCode == VK - LEFT && e.isShiftDown ()) {
...
The KeyEvent class provides several other useful methods such as the
isShiftDown() method used above and isActionKey() which indicates
whether the event was triggered by one of the action keys such as HOME , END ,
etc. See the KeyListener and KeyEvent class descriptions for more informa-
tion on using key data.
12.7 Audio
In the early versions of Java the audio capabilities in the core language were
extremely limited. Only 8 kHz au type files could be played. With version 1.2, it
became possible to play 22 KHz, 16-bit stereo in the following formats:
AIFF
AU
WAV
MIDI
RMF
The new sound engine is a part of the core library. A full featured Java
Sound API became available as well in Java 1.3. This includes the packages
javax.sound.midi and javax.sound.sampled . These advanced audio
capabilities are beyond the scope of this topic so we only look at the simple
playing of sound clips [2-5].
While audio may have limited applications for scientific programs, they can
be useful for such things as warnings and alarms. The AudioClip interface has
three methods to implement:
play ()
loop ()
stop ()
Search WWH ::




Custom Search