home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / promain.bin / DBVPO.DLL / SOURCE / SLIDESHOW < prev    next >
Text File  |  1998-03-18  |  2KB  |  104 lines

  1. import java.awt.Button;
  2. import java.awt.Dimension;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.Panel;
  7. import java.awt.FlowLayout;
  8. import java.awt.Toolkit;
  9. import java.net.URL;
  10. import java.net.MalformedURLException;
  11.  
  12.  
  13. public class SlideShow extends Panel
  14. {
  15.     protected ImageViewer viewer;
  16.     protected String fileNames[];
  17.     protected Image images[];
  18.     protected int count;
  19.  
  20.     public SlideShow()
  21.     {
  22.         try {
  23.             viewer = new ImageViewer();
  24.             setNumberOfImages(0);
  25.         } catch (Exception e)
  26.         {
  27.         }
  28.     }
  29.  
  30.     public void setNumberOfImages(int i)
  31.     {
  32.         fileNames = new String[i];
  33.         images    = new Image[i];
  34.     }
  35.  
  36.     public int getNumberOfImages()
  37.     {
  38.         return (fileNames.length);
  39.     }
  40.  
  41.     public void addFileName(String fileName)
  42.         throws MalformedURLException
  43.     {
  44.         fileNames[count]    = fileName;
  45.         images[count]        = getToolkit().getImage(new URL(fileNames[count]));
  46.         count++;
  47.     }
  48.  
  49.     public String[] getFileNames()
  50.     {
  51.         return (fileNames);
  52.     }
  53.  
  54.     public void display()
  55.         throws MalformedURLException
  56.     {
  57.         count = 0;
  58.         add(viewer);
  59.  
  60.         viewer.setImage(images[count]);
  61.     }
  62.  
  63.     protected void nextPressed()
  64.     {
  65.         viewer.setImage(images[++count]);
  66.  
  67.            Toolkit.getDefaultToolkit().getSystemEventQueue().
  68.             postEvent(new ActionEvent((java.awt.Window)getParent(),
  69.                                      ActionEvent.ACTION_PERFORMED,
  70.                                        new Integer(count).toString()));
  71.     }
  72.  
  73.     protected void prevPressed()
  74.     {
  75.         viewer.setImage(images[--count]);
  76.  
  77.            Toolkit.getDefaultToolkit().getSystemEventQueue().
  78.             postEvent(new ActionEvent((java.awt.Window)getParent(),
  79.                         ActionEvent.ACTION_PERFORMED,
  80.                           new Integer(count).toString()));
  81.     }
  82.  
  83.     public Dimension preferredSize()
  84.     {
  85.         if (viewer != null) {
  86.             Dimension d;
  87.             d = viewer.preferredSize();
  88.             return d;
  89.         }
  90.         return super.preferredSize();
  91.     }
  92.  
  93.     public void repaint()
  94.     {
  95.         super.repaint();
  96.         viewer.repaint();
  97.     }
  98.  
  99.     public void update(Graphics g)
  100.     {
  101.         paint(g);
  102.     }
  103. }
  104.