import java.awt.*;
import java.awt.image.*;public class jwmem extends java.applet.Applet 
{
   Image i;
   int width = 200;
   int height = 200;
   public void init() 
   {
      int[] pixels = new int[width * height];
      int c;
      double radianConversion = Math.PI / 180.0;
      for(int index = 0, y = 0; y < height; y ++ ) 
      {
         c = ((0xff) & (byte)(Math.abs(Math.sin((y + height) * radianConversion)) * 255));
         for(int x = 0; x < width; x ++ ) 
         {
            pixels[index++] = ((0xff << 24) | (c << 16) | (c << 8) | c);
         }
      }
      i = createImage(new MemoryImageSource(width, height, pixels, 0, width));
      setFont(new Font("TimesRoman", Font.BOLD | Font.ITALIC, 32));
   }
   public void paint(Graphics g) 
   {
      g.drawImage(i, 0, 0, this);
      g.drawString("JavaWorld", 30, 80);
   }
}

解决方案 »

  1.   

    import java.awt.*;
    import java.awt.image.*;public class jwmem2 extends java.applet.Applet 
    {
       Image i;
       int width = 200;
       int height = 200;
       public void init() 
       {
          byte[] pixels = new byte[width * height];
          int arraySize = 3;
          Color colorArray[] = new Color[arraySize];
          colorArray[0] = Color.green;
          for(int i = 1; i < arraySize; i ++ ) 
             colorArray[i] = colorArray[i - 1].darker();
          byte reds[] = new byte[arraySize];
          byte greens[] = new byte[arraySize];
          byte blues[] = new byte[arraySize];
          for(int i = 0; i < arraySize; i ++ ) 
          {
             reds[i] = (byte)colorArray[i].getRed();
             greens[i] = (byte)colorArray[i].getGreen();
             blues[i] = (byte)colorArray[i].getBlue();
          }
          for(int index = 0, y = 0; y < height; y ++ ) 
             for(int x = 0; x < width; x ++ ) 
                pixels[index++] = (byte)(x % arraySize);
          i = createImage(new MemoryImageSource(width, height, new IndexColorModel(8, arraySize, reds, greens, blues), pixels, 0, width));
          setFont(new Font("TimesRoman", Font.BOLD | Font.ITALIC, 32));
       }
       public void paint(Graphics g) 
       {
          g.drawImage(i, 0, 0, this);
          g.drawString("JavaWorld", 30, 80);
       }
    }
      

  2.   

    我想知道的是
    Image pImg[]; 的用法。
      

  3.   

    是否用错了
    abstract  boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) 
              Draws as much of the specified image as is currently available. 
    abstract  boolean drawImage(Image img, int x, int y, ImageObserver observer) 
              Draws as much of the specified image as is currently available. 
    abstract  boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) 
              Draws as much of the specified image as has already been scaled to fit inside the specified rectangle. 
    abstract  boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) 
              Draws as much of the specified image as has already been scaled to fit inside the specified rectangle. 
    abstract  boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) 
              Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. 
    abstract  boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) 
              Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. 
      

  4.   

    你没有错,我也没有错。
    byte[] pixels = new byte[width * height]; //图片点阵数组Image pImg[];     图片数组
      

  5.   

    Image pImg[];    图片数组
    如:
    pImg[1] = image1;
    pImg[2] = image2;
    pImg[3] = image3;