/** * CommandLineArgsTest.java * * @author Jeff Ondich * * Shows a brief example of how to use simple command-line arguments to determine * the behavior of your program. Plunder and modify as you wish. */ import java.io.*; import java.awt.*; public class ImageMultiProcessorTest { public static void main( String[] args ) throws IOException { // Make sure there are at least two command-line arguments (one for the // name of the image file, and one for the particular operation to perform). if( args.length < 2 ) { printUsageStatement(); return; } // Create the image. ImageMultiProcessor image = new ImageMultiProcessor( args[0] ); image.show( "Original", 10, 10 ); // Depending on the command-line arguments, modify the image // in some way. if( args[1].equals( "red" ) ) { image.removeGreenAndBlue(); } else if( args[1].equals( "green" ) ) { image.removeRedAndBlue(); } else if( args[1].equals( "crop" ) ) { if( args.length == 6 ) { int rowStart = Integer.parseInt( args[2] ); int rowStop = Integer.parseInt( args[3] ); int colStart = Integer.parseInt( args[4] ); int colStop = Integer.parseInt( args[5] ); if( !image.crop( rowStart, rowStop, colStart, colStop ) ) { System.out.println( "The specified row/column information does not fit within this image." ); } } else printUsageStatement(); } else if( args[1].equals( "gray" ) ) { image.gray(); } else if( args[1].equals( "mirror" ) ) { image.mirror(); } else { printUsageStatement(); } // Display the resulting image. image.show( "New version", 510, 10 ); } private static void printUsageStatement() { System.out.println( "" ); System.out.println( "Usage:" ); System.out.println( "java CommandLineArgsTest imagefile red -- shows the red component of the image" ); System.out.println( "java CommandLineArgsTest imagefile green -- shows the green component of the image" ); System.out.println( "java CommandLineArgsTest imagefile gray -- converts the image to grayscale" ); System.out.println( "java CommandLineArgsTest imagefile mirror -- creates a left-to-right mirror image" ); System.out.println( "java CommandLineArgsTest imagefile crop rowStart rowStop colStart colStop -- crops the image as directed by the specified integers" ); System.out.println( "" ); } }