import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.image.*; // Instantiate this class and then use the draw() method to draw the // generated on the graphics context. public class { // Holds the generated image Image image; // 16-color model; this method is defined in // Creating an Image from an Array of Color-Indexed Pixel Values ColorModel colorModel = generateColorModel(); public (int width, int height) { // Initialize with default location this(width, height, new Rectangle2D.Float(-2.0f, -1.2f, 3.2f, 2.4f)); } public (int width, int height, Rectangle2D.Float loc) { // Generate the pixel data; this method is defined in // Creating an Image from an Array of Color-Indexed Pixel Values byte[] pixels = generatePixels(width, height, loc); // Create a data buffer using the byte buffer of pixel data. // The pixel data is not copied; the data buffer uses the byte buffer array. DataBuffer dbuf = new DataBufferByte(pixels, width*height, 0); // The number of banks should be 1 int numBanks = dbuf.getNumBanks(); // 1 // Prepare a sample model that specifies a storage 4-bits of // pixel datavd in an 8-bit data element int bitMasks[] = new int[]{(byte)0xf}; SampleModel sampleModel = new SinglePixelPackedSampleModel( DataBuffer.TYPE_BYTE, width, height, bitMasks); // Create a raster using the sample model and data buffer WritableRaster raster = Raster.createWritableRaster(sampleModel, dbuf, null); // Combine the color model and raster into a buffered image image = new BufferedImage(colorModel, raster, false, null);//new java.util.Hashtable()); } public void draw(Graphics g, int x, int y) { g.drawImage(image, x, y, null); } }