home *** CD-ROM | disk | FTP | other *** search
/ Magazyn WWW 2000 June / www-06-2000.iso / java / Main.java < prev    next >
Text File  |  2000-04-11  |  856b  |  36 lines

  1. import java.awt.*;
  2. import java.io.*;
  3.  
  4. public class Main extends Component {
  5.  
  6.     private Image image;
  7.  
  8.     public Main() {
  9.         setBackground(Color.yellow);
  10.     }
  11.  
  12.     public void paint(Graphics g) {
  13.         if (image==null) {
  14.             ByteArrayOutputStream bytes=new ByteArrayOutputStream();
  15.             byte[] buffer=new byte[1024];
  16.             int count;
  17.             InputStream is=getClass().getResourceAsStream("Anim.gif");
  18.             try {
  19.                 do {
  20.                     count=is.read(buffer);
  21.                     if (count>0) {
  22.                         bytes.write(buffer, 0, count);
  23.                     }
  24.                 } while (count>=0);
  25.             } catch (IOException ex) {
  26.                 ex.printStackTrace();
  27.             } finally {
  28.                 try { is.close(); } catch (IOException ex) {}
  29.             }
  30.             image=getToolkit().createImage(bytes.toByteArray());
  31.             try { bytes.close(); } catch (IOException ex) {}
  32.         }
  33.         g.drawImage(image, 0, 0, getSize().width, getSize().height, this);
  34.     }
  35. }
  36.