// Read a file containing rectangle paint commands // and draw them in a Drawing Panel // See RectanglePainter.java for final solution // Step 4: Make file processing code its own method import java.util.*; import java.io.*; public class Paint4 { public static void main(String[] args) throws FileNotFoundException { String fileName = getFileName(); processFile(fileName); } public static String getFileName() { Scanner console = new Scanner(System.in); System.out.print("File name: "); return console.next(); } public static void processFile(String fileName) throws FileNotFoundException { Scanner fileScan = new Scanner(new File(fileName)); String line = fileScan.nextLine(); Scanner lineScan = new Scanner(line); int width = lineScan.nextInt(); int height = lineScan.nextInt(); System.out.println("width: " + width + ", " + height); DrawingPanel p = new DrawingPanel(width, height); while (fileScan.hasNextLine()) { line = fileScan.nextLine(); processLine(line); } } public static void processLine(String line) { System.out.println(line); } }