View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Weird Generic Lack of Warning

//Shouldn't this cause an error or warning? Note the type of List created in main, and the variable in the Class.
import java.util.*;
/*** Class that represents a slide show.  A slide show has
 *   an array of pictures, a time to wait between pictures,*  and a title that is shown at the beginning of the show.
 ** @author Barb Ericson 
 */
public class NewSlideShow //implements List
{
  ///////////// fields //////////////
  private List<Picture>pictList;
  private int waitTime = 2000;
  private String title;
  
  ///////////// constructors /////////
  
  /*** A no-argument constructor that takes
   *no parameters and leaves fields with their* default values
   */
  public NewSlideShow()
  {}
  
  /*** Constructor that takes the array of
   *pictures* @param pictArray the array of pictures
   */
  public NewSlideShow(List pictList)
  {
    this.pictList = pictList;
  }
  
   
  /*** A constructor that takes the array of 
   *pictures and a title* @param pictArray the array of pictures
   *@param theTitle the title to use
   */
  public NewSlideShow(List pictList,
                   String theTitle)
  {
    this.pictList = pictList;
    this.title = theTitle;
  }
  
  /**
   *Constructor that takes the array of* pictures, the wait time, and the title
   *@param pictArray the array of pictures
   * @param time the time to wait between 
   *pictures in milliseconds* @param theTitle the title for the window
   */
  public NewSlideShow(List pictList,
                   int time,
                   String theTitle)
  {
    this.pictList = pictList;
    this.waitTime = time;
    this.title = theTitle;
  }
  
  ////////////////// methods ////////////////
  
  /*** Method to show the slide show information
   *in a string (the number of pictures* and the wait time)
   */
  public String toString()
  {
    String result = "A slide show ";
    if (this.title != null) 
      result = result + "titled: " + this.title;
    if (this.pictList != null)
      result = result + " with " + 
               this.pictList.size() + 
               " slides ";
    result = result + 
      "a wait time of " + this.waitTime;
    return result;
  }
  
  /*** Method to get the wait time
   *@return the time to wait between pictures
   */
  public int getWaitTime()
  {
    return this.waitTime;
  }
  
  /** 
   *Method to get a picture at an index* in the array of pictures
   *@param index the index to use
   * @return the picture at the index
   */
  public Picture getPicture(int index)
  {
    Picture pict = null;
    if (this.pictList != null &&
        index  this.pictList.size())
    {
      pict = this.pictList.get(index);
    }
    return pict;
  }
  
  /*** Method to set the array of pictures
   *@param pictArray the array to use
   * @return true if success else false
   */
  public boolean setPictureArray(List pictList)
  {
    boolean result = false;
    if (this.pictList == null)
    {
      this.pictList = pictList;
      result = true;
    }
    return result;
  }
  
  /*** Method to change the time to wait
   *between pictures* @param time the new time to use
   *in milliseconds*/
  public void setWaitTime(int time)
  {
    if (time >= 0)
       this.waitTime = time;
  }
       
  /**
   *Method to show the slide show*/
  public void show() throws Exception
  {
    // check that the picture array isn't null
    if (pictList != null)
    {
      
      // if the title isn't null show it
      if (title != null)
      {
        Picture titleP = new Picture(640,480);
        titleP.drawHorizontalCenteredString(title,240);
        titleP.show();
        Thread.sleep(this.waitTime);
        titleP.hide();
      }
      
      /** Loop through the pictures */
      for (Picture currPict : this.pictList)
      {
        currPict.show();
        Thread.sleep(waitTime);
        currPict.hide();
      }
    }
  }
  
  /*** Main method for testing 
   /
  public static void main(String[] args) throws Exception
  {
    List pictList = new ArrayList();
    pictList.add(new Picture(FileChooser.getMediaPath("beach.jpg")));
    pictList.add(new Picture(FileChooser.getMediaPath("blueShrub.jpg")));
    pictList.add(new Picture(FileChooser.getMediaPath("church.jpg")));
    pictList.add(new Picture(FileChooser.getMediaPath("eiffel.jpg")));
    pictList.add(new Picture(FileChooser.getMediaPath("greece.jpg")));
    pictList.add(new Picture(FileChooser.getMediaPath("flower1.jpg")));
    pictList.add(new Picture(FileChooser.getMediaPath("flower2.jpg")));    
    NewSlideShow vacShow = new NewSlideShow(pictList,"Vacation Slides");
    vacShow.show();
  }
}
    

NewSlideShow.java

Link to this Page