import java.awt.*; import java.awt.image.*; import javax.imageio.ImageIO; import java.io.File; import java.io.IOException; class Main { static final int X = 256, Y = 256; static BufferedImage I = new BufferedImage(X, Y, BufferedImage.TYPE_BYTE_GRAY); static public void main( String[] args ) { Frame f = new Frame( "paint Example" ); f.add("Center", new MainCanvas()); f.setSize(new Dimension(X,Y+22)); for (int i = 0; i 0) try {ImageIO.write(I, "png", new File(args[0]));} catch (IOException e) {System.err.println("image not saved.");} for(int q=0; q < args.length; ++q) { int z = args[q].lastIndexOf('.'); if (z > 0) try {ImageIO.write( I, args[q].substring(z+1), new File(args[q]));} catch (IOException e) {System.err.println("image not saved.");} else System.err.println( "Command line argument not a graphics file name");}}} class MainCanvas extends Canvas{ public void paint(Graphics g){ g.drawImage(Main.I, 0, 0, Color.red, null);}}