█████████
█┏━━━━━┓█
█★          ★█
█    ☆  ☆    █
█              █
█ 〖初窥Java〗 █
█ 【虚心学习】 █
█★          ★█
█┗━━━━━┛█
█████████

解决方案 »

  1.   

    refer to following example, the example is to create an image.
    import java.awt.*;
    import java.awt.image.*;/**
     * <strong>MemoryImageExample</strong> -- creating an image from
     * raw pixel data.
     *
     * <p>
     * This example creates a 29-by-29 array of pixels and displays it in
     * an image magnified by a factor of 8.  The pixel indices progress
     * from left to right in a row, and from higher row to lower row.
     * 
     * <p>
     * The pixels have red turned on if the index is divisible by 2, green
     * turned on if the index is divisible by 3, and blue turned on if the
     * index is divisible by 5.  Note, for instance, that every thirtieth
     * pixel is white (divisible by 2, 3, and 5) and is surrounded by
     * black pixels (index divisible by NONE of 2, 3, and 5).
     */
    public class MemoryImageExample extends java.applet.Applet {    static final int opaque = 0xFF << 24;
        static final int red = 0xFF << 16;
        static final int green = 0xFF << 8;
        static final int blue = 0xFF;    Image myImage;    public void init() {
    myImage = buildImage();
        }    public void paint(Graphics g) {
    g.drawImage(myImage, 4, 4, 232, 232, this);
        }    Image buildImage() {
    int width = 29;
    int height = 29;
    int[] pixels = new int[width * height]; /* Set pixel color according to divisibility by 2, 3,
     * and 5.
     */
    for (int i = 0; i < width * height; ++i) {
        int val = opaque; /* current pixel value */
        if (i % 2 == 0)  val |= red;
        if (i % 3 == 0)  val |= green;
        if (i % 5 == 0)  val |= blue;
        pixels[i] = val;
    }
    return createImage(new MemoryImageSource(width, height,
     pixels, 0, width));
        }}