刚到美国读书,选了一门课叫Foundations of Distributed Applications.第一次作业我就没有看懂,不知道用什么来实现,请大家点拨一下。我刚开始学java,请大家给一些详细的指导。我已经下载了JDK,和eclipse,但用什么实现呢?没有头绪。Assign1: Serialization in Java
DescriptionThe objectives of this assignment include:Explore serialization and deserialization in Java.Become familiar with Java Swing user interface components, including JTree and JComboBox.Utilize class files for which you don't have the corresponding source code.In this assignment, you are to implement classes that support media file descriptions, with the functionality to save and restore using an Xml file. Save and restore should be done by using Java serialization. You are to create an Xml serializable Library class, where the library is a collection ofMediaDescription objects. Your solution should define and implement the classes defined below.Classes
In your solution to this problem, include three classes described below:
MediaDescription. MediaDescription objects contain information that describes media files such Video and Music. Your class should have properties for the following
category. What type of media is being described. We will use Music, and Video as the two primary categories. Category should be a string value.
subcategory. A description within the category. For example the Video category may have Action and Comedy subcategories. The Music category may have Rock and Classical subcategories. Subcategory should be a string value.
title. The string title of the media. For example, "Tomorrow Never Dies."
author. The string author of the media.
comment. A string that describes anything unique about the media file.
urlFile. A string providing a URL of the media file, such as: http://myhost.com/myvideofile.m4v or a file URL such as:file:///Users/lindquis/MyMusic/mymusicfile.mp3.
album. A string naming the album, if its a music file.Provide getter and setter methods for all properties in this class.
Library. The Library class will have a single object in your solution, which contains a collection of MediaDescription objects.
MediaLibraryApp. The MediaLibraryApp class extends the instructor provided MediaLibraryGui class. Use the SampleAssign1 class as a prototype for this class, which can be found in the sample project.Your solution should include class/interface header javadoc comments that provide author and version comments, as well as a brief description of the class. You should provide these comments for all classes and interfaces that you create for this class.LibraryThe library class should have specific methods to support serialization and deserialization. Serialize a Library object to a file in the project directory. Deserialization should read in the file re-initializing a Library object. In future assignments, you will build on the library class making it part of a client-server distributed application. In doing so, you will need to create methods in your library class that allow media to be added to and removed from the collection. You can provide these methods now if it helps you solve this problem, but they are not needed to complete this assignment. For example, to solve this problem, you may implement the following methods in your Library class: public MediaDescription getMediaByTitle(String title);public void addMedia(MediaDescription aMediaWork);
public void removeMedia(String title);public String[] getAvailableTitles();
public void save(OutputStream os); //saves the library of media descriptions to a (file) output stream
a constructor Library (InputStream is); //recovers the library of media descriptions from a (file) input streamYour library should be serializable, and should support serialization to/from Xml. Calling save should cause the library (and all of its media descriptions) to be serialized to an Xml stream. Similarly, the library can be re-constructed from an input stream of Xml bytes.MediaLibraryGui
The MediaLibraryGui is a Swing user interface (extends JFrame) that can be used to browse media. The MediaLibraryGui has a File menu with only two menu items. The File menu items are Save and Restore. Selecting Save should cause the current Library to be serialized to an Xml file. Selecting the Restoremenu item should cause the current Library to be initialized from the Xml file. Below is a sample of the gui. The class file for the LibraryGui is provided by the instructor, along with an example Java program that demonstrates using the GUI. Below is an example showing the JTable control of the LibraryGui class.
Here is a sample project that includes a build file, sampleBuild.xml, a sample main program SampleLibrary.java, together with an included jar file containing the Gui class, and a doc directory with javadocs for the Gui class. To build and run the sample, extract the jar file and from the command line in the Assign1 directory execute: ant -f sampleBuild.xml execute. Note that the sample build file constructs a class path that includes the Gui classes that are found in the lib directory. This classpath is used for compiling and executing. See: sampleAssign1.jarHere are the javadocs for MediaLibraryGui.Structure of your Solution Directory
You should submit your solution as a jar file with an Ant build.xml file for grading purposes. The project directory should be Assign1 (case sensitive) and should include only the following files, subdirectories and classes:
subdirectory: src for source files. The src directory contains all of the java files in your solution.
subdirectory: lib used to store the jar file containing classes for the instructor provided user interface.
subdirectory classes used to store the compiled Java class files.build.xml Ant build file with the targets specified above.What To Hand-In
You will hand-in this program by uploading a jar file using the upload assignment page. Take note that you may upload only one file for each assignment. Upload is only enabled for one week. The week ends at the end of the day (midnight) that the assignment is due. The upload page will not accept uploads greater than 500KB, and the mime type of the uploaded file must be either application/x-zip-compressed (Internet Explorer's default for jar and zip files) or application/zip (for Mozilla, firefox, Netscape, see Edit->Preferences Helper Applications.) You may want to assure that uploading works for your browser by uploading a file to the Guest account. Guest is set to allow multiple file uploads.When extracted, your solution jar file should create the directory Assign1 with only your solution files as specified above. Create your jar file from a command line whose current working directory is Assign1's parent directory. Execute the command:
jar -cvf assign1sol.jar Assign1

解决方案 »

  1.   

    要什么类、类中有什么属性都告诉你了,你要做的就是实现逻辑就行了,swing简单看看,看哪些控件也都说了。最后就是用个xml API,把媒体信息持久化到磁盘,然后再读出来就行了。剩下的怎么用ant编译,怎么交作业你就比我清楚了
      

  2.   


    class MediaDescription{
    private String category;
    private String subcategory;
    private String title;
    private String author;
    private String comment;
    private String urlFile;
    private String album;
    setter ...
    getter ...
    }
    abstract class Library implements Serializable{
    private InputStream is;
    private Library(InputStream is){
    this.is = is;
    }
    Map<String, MediaDescription> medias = new HashMap<String, MediaDescription>();
    private static Library instance = new LibraryImpl();
    public static Library newInstance(){
    return instance;
    }
    public abstract MediaDescription getMediaByTitle(String title);
    public abstract void addMedia(MediaDescription aMediaWork);
    public abstract void removeMedia(String title);
    public abstract String[] getAvailableTitles();
    public abstract void save(OutputStream os);
    static class LibraryImpl extends Library{
    //Override abstract methods
    }
    }class MediaLibraryApp extends MediaLibraryGui{

    }
    class MediaLibraryGui extends JFrame{
    }just a sample
    The specific implementation involves a lot of knowledge
    such as io/swing/xml/serialization, However it's not so difficult!!
      

  3.   

    可以用JTree来完成左边的树状图。