/** Print the demo page */ public void printDemoPage() { // Create the HardcopyWriter, using a 10 point font and 3/4" margins. HardcopyWriter hw; try { hw = new HardcopyWriter(this, "Demo Page", 14, .75, .75, .75, .75); } catch (HardcopyWriter.PrintCanceledException e) { return; } // Send output to it through a PrintWriter stream PrintWriter out = new PrintWriter(hw); // Figure out the size of the page int rows = hw.getLinesPerPage(), cols = hw.getCharactersPerLine(); // Mark upper left and upper-right corners out.print("+"); for (int i = 0; i < cols - 2; i++) out.print(" "); out.print("+"); // Display a title hw.setFontStyle(Font.BOLD + Font.ITALIC); out.println("\n\n\n\t\tHardcopy Writer Demo Page\n\n\n\n\n"); // Demonstrate font styles hw.setFontStyle(Font.BOLD); out.println("Font Styles:"); int[] styles = {Font.PLAIN, Font.BOLD, Font.ITALIC, Font.ITALIC + Font.BOLD}; for (int i = 0; i < styles.length; i++) { hw.setFontStyle(styles[i]); out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); out.println("1234567890!@#$%^&*()[]{}<>,.?:;+-=/\\`'\"_~|"); } hw.setFontStyle(Font.PLAIN); out.println("\n\n"); // Demonstrate tab stops hw.setFontStyle(Font.BOLD); out.println("Tab Stops:"); hw.setFontStyle(Font.PLAIN); out.println(" 1 2 3 4 5"); out.println("01234567890123456789012345678901234567890123456789012345"); out.println("^\t^\t^\t^\t^\t^\t^"); out.println("\n\n"); // Output some information about page dimensions and resolution hw.setFontStyle(Font.BOLD); out.println("Dimensions:"); hw.setFontStyle(Font.PLAIN); out.println("\tResolution: " + hw.pagedpi + " dots per inch"); out.println("\tPage width (pixels): " + hw.pagesize.width); out.println("\tPage height (pixels): " + hw.pagesize.height); out.println("\tWidth inside margins (pixels): " + hw.width); out.println("\tHeight inside margins (pixels): " + hw.height); out.println("\tCharacters per line: " + cols); out.println("\tLines per page: " + rows); // Skip down to the bottom of the page for (int i = 0; i < rows - 37; i++) out.println(); // And mark the lower left and lower right out.print("+"); for (int i = 0; i < cols - 2; i++) out.print(" "); out.print("+"); // Close the output stream, forcing the page to be printed out.close(); }