Home Segments Top Top Previous Next

865: Mainline

With the interface defined, you proceed to define the required class. If the file name supplied is different from the current value of the file variable, and is not null, then setImage creates an image using that argument and the readMovieImage auxiliary defined in Segment 844. Then, the setter calls repaint, which in turn calls paint.

import java.awt.*; 
import javax.swing.*; 
import java.util.*; 
public class Poster extends JComponent implements PosterInterface { 
 private String file; 
 private Image image; 
 public void setImageFile (String s) { 
  if (s != file) { 
   file = s; 
   if (file == null) {image = null;} 
   else { 
    image = MovieAuxiliaries.readMovieImage(file); 
   } 
   repaint(); 
  } 
 } 
 // Definition of paint 
 } 
 public Dimension getMinimumSize() {return new Dimension(200, 300);} 
 public Dimension getPreferredSize() {return new Dimension(200, 300);} 
}