Java Reference
In-Depth Information
final Hyperlink link = new Hyperlink("About Code Monkey...");
link.setOnAction((ActionEvent event) -> {
WebView wv = new WebView();
wv.getEngine().load("
http://www.jonathancoulton.com/2006/04/14/
"
+
"thing-a-week-29-code-monkey/");
Scene scene = new Scene(wv, 720, 480);
Stage stage = new Stage();
stage.setTitle("Code Monkey");
stage.setScene(scene);
stage.show();
});
vbox.getChildren().addAll(clipLabel, getUpButton, goToJobButton,
meetingButton, link);
GridPane.setHalignment(vbox, HPos.CENTER);
GridPane.setHgrow(vbox, Priority.ALWAYS);
GridPane.setVgrow(vbox, Priority.ALWAYS);
grid.add(vbox, 0, 0, GridPane.REMAINING, 1);
}
private EventHandler<ActionEvent> createPlayHandler(final AudioClip clip) {
return (ActionEvent event) -> {
clip.play(volumeSlider.getValue(), balanceSlider.getValue(),
rateSlider.getValue(), 0, 0);
};
}
As each
Button
is created, a new
EventHandler
is also created that plays the appropriate
AudioClip
for that
Button
. The
play
method in the
EventHandler
uses the current values of the volume, rate, and balance sliders as its
arguments. The last two arguments of the
play
method are set to zero, but these can be used to specify the
pan
and
priority
of the
AudioClip
when it is played. We discuss these two properties in the next section.
AudioClip
Wrap-Up
There are two properties of an
AudioClip
that we have not shown in the preceding examples:
pan
and
priority
. The
pan
property allows you to move the center of your clip. Setting it to -1.0 moves the clip completely to the left channel,
and setting it to 1.0 moves it completely to the right. The default setting of 0.0 leaves the clip as it was originally. Unlike
the
balance
property, which merely adjusts the relative volumes of the left and right channels, the
pan
property
actually remixes the two channels. This allows you to introduce some or all of the left channel into the right channel
and vice versa. It really only makes sense to use the
pan
property on actual stereo sound effects with right and left
channels that differ. Setting the pan on a mono sound has the exact same outcome as adjusting the balance, and
balance is much less computationally expensive. You can set or retrieve a clip's current pan setting using the
setPan
and
getPan
methods and the property is exposed by the
panProperty
method.
You can optionally assign a priority to your
AudioClip
s. This is an
IntegerProperty
that specifies the relative
priority of your sound effects. The higher the number, the more importance you are assigning to that
AudioClip
. If you
exceed the limit of
AudioClip
playbacks that the system can handle, the priorities are used to determine which clips
are stopped. The number of clips that can be played is not specified precisely, nor can it be queried in the current
version of JavaFX. Therefore, if you play a lot of
AudioClip
s at once, as might be the case for a game, you should
consider assigning priorities to your sound effects.
Search WWH ::
Custom Search