Java Reference
In-Depth Information
Example 12−3: HardcopyWriter.java (continued)
**/
public static class PrintFile {
public static void main(String[] args) {
try {
if (args.length != 1)
throw new IllegalArgumentException("Wrong # of arguments");
FileReader in = new FileReader(args[0]);
HardcopyWriter out = null;
Frame f = new Frame("PrintFile: " + args[0]);
f.setSize(200, 50);
f.show();
try {
out = new HardcopyWriter(f, args[0], 10, .5, .5, .5, .5);
}
catch (HardcopyWriter.PrintCanceledException e) {
System.exit(0);
}
f.setVisible(false);
char[] buffer = new char[4096];
int numchars;
while((numchars = in.read(buffer)) != -1)
out.write(buffer, 0, numchars);
in.close();
out.close();
}
catch (Exception e) {
System.err.println(e);
System.err.println("Usage: " +
"java HardcopyWriter$PrintFile <filename>");
System.exit(1);
}
System.exit(0);
}
}
/**
* A program that prints a demo page using HardcopyWriter
**/
public static class Demo extends Frame implements ActionListener {
/** The main method of the program. Create a test window */
public static void main(String[] args) {
Frame f = new Demo();
f.show();
}
// Buttons used in this program
protected Button print, quit;
/** Constructor for the test program's window. */
public Demo() {
super("HardcopyWriter Test");
// Call frame constructor
Panel p = new Panel();
// Add a panel to the frame
this.add(p, "Center");
// Center it
p.setFont(new Font("SansSerif",
// Set a default font
Font.BOLD, 18));
print = new Button("Print Test Page"); // Create a Print button
quit = new Button("Quit");
// Create a Quit button
print.addActionListener(this);
// Specify that we'll handle
quit.addActionListener(this);
//
button presses
Search WWH ::




Custom Search