Java Reference
In-Depth Information
} catch (RuntimeException re) {
// Handle construction errors
System.out.println("Caught Exception: " + re.getMessage());
}
}
private void handleMetadata(String key, Object value) {
switch (key) {
case "album":
setAlbum(value.toString());
break;
case "artist":
setArtist(value.toString());
break;
case "title":
setTitle(value.toString());
break;
case "year":
setYear(value.toString());
break;
case "image":
setAlbumCover((Image)value);
break;
}
}
}
The MediaPlayer property is exposed as a ReadOnlyObjectProperty inasmuch as we don't want users of the class
to be able to set the MediaPlayer instance to a new value. Now that we have a nicely encapsulated class for our media,
we turn our attention to separating our UI code into more manageable chunks, or views . A new AbstractView base
class is created to eliminate duplication by holding some code that is common to all of our views. This small class is
shown in Listing 9-11.
Listing 9-11. The AbstractView Base Class
public abstract class AbstractView {
protected final SongModel songModel;
protected final Node viewNode;
public AbstractView(SongModel songModel) {
this.songModel = songModel;
this.viewNode = initView();
}
public Node getViewNode() {
return viewNode;
}
protected abstract Node initView();
}
 
Search WWH ::




Custom Search