i have just learned how to print a text ( not a text file ) in Java, and i also have just learned how to make a program with GUI using AWT and SWING ( i understand only a little bit of those two techniques, just adequate for me to make my program works
).
now what i'm trying to do is to make a GUI program that prints an ArrayList's contents when i push a 'PRINT' button.
the bottomline of my case is that i need to know how to make a print method with an ArrayList parameter which contents is going to be print.
let me simplify more :
say i have this program i used to print
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;
public class PrintInvoice {
private final static int POINTS_PER_CM = 29;
public PrintInvoice () {
PrinterJob printJob = PrinterJob.getPrinterJob ();
Book book = new Book ();
PageFormat documentPageFormat = new PageFormat ();
documentPageFormat = printJob.pageDialog(documentPageFormat);
for(int j=0; j<10; j++)
book.append (new IntroPage (), documentPageFormat);
printJob.setPageable (book);
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception PrintException) {
PrintException.printStackTrace();
}
}
}
static public void main(String args[])
{
PrintInvoice ex = new PrintInvoice();
}
private class IntroPage implements Printable {
public int print (Graphics g, PageFormat pageFormat, int page) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());
g2d.setPaint (Color.black);
Font titleFont = new Font ("Times New Roman", Font.BOLD, 14);
g2d.setFont (titleFont);
g2d.drawString ("text1", (int)(17.5*POINTS_PER_CM), (int)(2*POINTS_PER_CM));
titleFont = new Font ("Times New Roman", Font.PLAIN, 11);
g2d.setFont (titleFont);
g2d.drawString ("text2", (int)(2.5*POINTS_PER_CM), (int)(2.6*POINTS_PER_CM));
g2d.drawString ("text3", (int)(2.5*POINTS_PER_CM), (int)(3.1*POINTS_PER_CM));
titleFont = new Font ("Times New Roman", Font.PLAIN, 10);
g2d.setFont (titleFont);
for (int i = (6*POINTS_PER_CM); i < (int)(11.5*POINTS_PER_CM); i += 14) {
g2d.drawString ("texta", (int)(1*POINTS_PER_CM), i);
g2d.drawString ("textb", (int)(1.9*POINTS_PER_CM), i);
g2d.drawString ("textc", (int)(2.9*POINTS_PER_CM), i);
}
titleFont = new Font ("Times New Roman", Font.PLAIN, 11);
g2d.setFont (titleFont);
g2d.drawString ("text4", (int)(18.5*POINTS_PER_CM), (int)(12.2*POINTS_PER_CM));
g2d.drawString ("text5", (int)(18.5*POINTS_PER_CM), (int)(12.7*POINTS_PER_CM));
g2d.drawString ("text6", (int)(18.5*POINTS_PER_CM), (int)(13.2*POINTS_PER_CM));
return (PAGE_EXISTS);
}
}
}
you will see that i'm printing "text1","text2",etc in a certain position, now i want to replace those texts with caontents from an ArrayList. can somebody give me some hints,codes,links,examples,explanations,or anything that might help?
any help would be great thank you very much