Printing an array of strings
Yesterday i’ve been experimenting with Printing on the Java Platform. I needed to generate a printout of ordered menuitems on the default printer. It took a while before i found out there is translation needed between the coordinates of the Graphics device and the PageFormat. Here is my LinesPrinter. Here is an example of how you can use the class
ArrayList<string> lines = new ArrayList<string>();
StringBuffer buf = new StringBuffer("De RegaPan\t");
buf.append(DateFormat.getDateTimeInstance().format(new Date()));
lines.add(buf.toString());
lines.add("");
DecimalFormat df = new DecimalFormat("##.00");
Enumeration e = billModel.elements();
while (e.hasMoreElements()) {
Order o = (Order) e.nextElement();
MenuItem mi = o.getMenuItem();
buf = new StringBuffer(mi.getName());
buf.append("\t");
buf.append(df.format(mi.getPriceIncVat()));
lines.add(buf.toString());
}
lines.add("\t-------");
lines.add("\t" + df.format(getTotal()));
LinesPrinter.print((String[]) lines.toArray(new String[0]));