Java Reference
In-Depth Information
public static void main(String[] args) {
CodeMonkeyToDo.launch(args);
}
public CodeMonkeyToDo() {
coffeeClip = new AudioClip(getClipResourceString("resources/coffee.mp3"));
jobClip = new AudioClip(getClipResourceString("resources/job.mp3"));
meetingClip =
new AudioClip(getClipResourceString("resources/meeting.mp3"));
}
// Scene construction code removed for now...
private String getClipResourceString(String clipName) {
return getClass().getResource(clipName).toString();
}
}
Constructing the Scene
We now take a brief look at the scene construction code for the application shown in Figure 9-2 . The application is
organized as a vertical column of buttons that play the audio clips with a row of controls at the bottom of the window.
We use a GridPane as the top-level layout container for the application. You can see the GridPane created in the
application's start method, which is shown in Listing 9-4. Once the GridPane is created and configured, it is passed
as an argument to the createControls and createClipList methods. The createClipList method is responsible for
creating the vertical column of buttons and is shown and discussed later in this section. The createControls method
creates Label s and the corresponding Slider controls that allow the user to set the volume, rate, and balance of the
next clip to be played. The Slider s and their Label s are then added to the GridPane before the method returns. After
the grid has been populated with its controls, it is used as the root node of a new Scene . The Scene is then styled with
our media.css style sheet and added to the primaryStage , which is then shown to the user.
Listing 9-4. Constructing the Scene and the Volume, Balance, and Rate Controls
@Override
public void start(Stage primaryStage) {
final GridPane grid = new GridPane();
grid.setPadding(new Insets(10));
grid.setHgap(10);
grid.setVgap(5);
createControls(grid);
createClipList(grid); // Shown later...
final Scene scene = new Scene(grid, 640, 380);
scene.getStylesheets()
.add(getClass().getResource("media.css").toString());
primaryStage.setTitle("AudioClip Example");
primaryStage.setScene(scene);
primaryStage.show();
}
 
Search WWH ::




Custom Search