Java Reference
In-Depth Information
Exercise 11.64 Implement a slide-show function that lets you choose a directory and then
displays each image in that directory for a specified length of time (say, 5 seconds).
Exercise 11.65 Once you have the slide show, add a slider (class JSlider ) that lets you
select an image in the slide show by moving the slider. While the slide show runs, the slider
should move to indicate progress.
Another example: MusicPlayer
So far in this chapter, we have discussed one example of a GUI application in detail. We now
want to introduce a second application to provide another example to learn from. This program
introduces a few additional GUI components.
This second example is a music-player application. We shall not discuss it in any great amount
of detail. It is intended as a basis for studying the source code largely on your own and as a
source of code fragments for you to copy and modify. Here, in this chapter, we shall only point
out a few selected aspects of the application that are worth focusing on.
Exercise 11.66 Open the musicplayer project. Create an instance of MusicPlayerGUI ,
and experiment with the application.
The musicplayer project provides a GUI interface to classes based on the music-organizer pro-
jects from Chapter 4. As there, the program finds and plays MP3 files stored in the audio folder
inside the project folder. If you have sound files of the right format of your own, you should be
able to play them by dropping them in the project's audio folder.
The music player is implemented across three classes: MusicPlayerGUI , MusicPlayer , and
MusicFilePlayer . Only the first is intended to be studied here. MusicFilePlayer can be
used essentially as a library class; instances are created along with the name of the MP3 file to
be played. Familiarize yourself with its interface, but you do not need to understand or modify
its implementation. (You are welcome, of course, to study this class as well if you like, but it
uses some concepts that we shall not discuss in this topic.)
Following are some noteworthy observations about the musicplayer project.
Model/view separation
This application uses a better model/view separation than the previous example. This means
that the application functionality (the model) is separated cleanly from the application's user
interface (the GUI). Each of those two, the model and the view, may consist of multiple classes,
but every class should be clearly in one or the other group to achieve a clear separation. In our
example, the view consists of a single GUI class.
Separating the application's functionality from the interface is an example of good cohesion;
it makes the program easier to understand, easier to maintain, and easier to adapt to different
requirements (especially different user interfaces). It would, for example, be fairly easy to write
Search WWH ::

Custom Search