Java Reference
In-Depth Information
In our example, we have placed our track list into a scroll pane. The scroll pane itself is then
placed into its parent container. The scrollbars only become visible when necessary. You can try
this by either adding more tracks until they do not fit into the available space or by resizing the
window to make it too small to display the current list.
Other elements demonstrated in this example are the use of a slider (which does not do much),
and the use of color for changing the look of an application. Each of the GUI's elements has
many methods for modifying the component's look or behavior—you should look through
the documentation for any component that interests you and experiment with modifying some
properties of that component.
Exercise 11.67 Change the music player so that it displays a different image in its center.
Find an image on the web to use, or make your own.
Exercise 11.68 Change the colors of the other components (foreground and background
colors) to suit the new main image.
Exercise 11.69 Add a new component to display details of the current track when one is
Exercise 11.70 Add a reload capability to the music player that rereads the files from the audio
folder. Then you can drop a new file into the folder and load it without having to quit the player.
Exercise 11.71 Add an Open item to the file menu. When activated, it presents a file-
selection dialog that lets the user choose a sound file to open. If the user chooses a directory,
the player should open all sound files in that directory (as it does now with the audio directory).
Exercise 11.72 Modify the slider so that the start and end (and possibly other tick marks)
are labeled with numbers. The start should be zero, and the end should be the length of the
music file. The MusicPlayer class has a getLength method. Note that the slider is not
currently functional.
Exercise 11.73 Modify the music player so that a double click on a list element in the track
list starts playing that track.
Exercise 11.74 Improve the button look. All buttons that have no function at any point in
time should be grayed out at that time and should be enabled only when they can reasonably
be used.
Exercise 11.75 The display of tracks is currently simply a JList of String objects.
Investigate whether there are any Swing components available that would provide greater
sophistication than this. For instance, can you find a way to provide a header line and align the
artist, title, and other parts of the track information? Implement this in your version.
Exercise 11.76 Challenge exercise Have the position slider move as a track is being played.
Search WWH ::

Custom Search