Displaying Pictures with AWT

      

/***********************************
Demonstrates how pictures can be displayed in a standard AWT Frame.
These commands are NOT suitable for animation, as they
images are not redrawn automatically and smoothly enough.
The basic idea is to CHANGE the pictures or positions,
and then use REPAINT to redisplay the page.
*************************************/

import java.awt.*;

public class ShowPics extends EasyApp
{
   public static void main(String[] args)
   {  new ShowPics(); }
   
   Button move = addButton("Move",500,100,80,50,this);
   
   Image redPic = Toolkit.getDefaultToolkit().getImage("img1.gif");
   Image greenPic = Toolkit.getDefaultToolkit().getImage("img2.gif");
   
   int redx=100, redy=100, greenx=300, greeny=100;
   
   public void actions(Object source,String command)
   {
      if (source == move)
      {   redy = redy + 20; }
      
      repaint();
   }
   
   public ShowPics()
   {  
      setSize(600,600);
   }
   
   public void paint(Graphics g)
   {
      try
      {
         g.drawImage(redPic, redx,redy, getBackground(), this);
         g.drawImage(greenPic, greenx,greeny, getBackground(), this);
      }
      catch (Exception ex)
      {}        
   }
   
}