ActionListener Events & PrinterJob

My Swing GUI will print one or more pages of photographs placed in a mug shot directory of multiple pages.  A user might request to print 2 copies of page 2, 4 copies of page 6, and 1 copy of page 8.  Then, they would input the page numbers to print, and number of copies for each page number, in text fields.  After that, they would click the Print button.  That is how I want it to work

I have included below the current print button action listener.  The problem I have is that the pj.printDialog pops up for every page to be printed.  

To make it easier to explain what I want, here's a scenario.  The user wants to...

* Print 3 copies of page 2.
* Print 4 copies of page 5.

Here are the events, as I would like them to transpire...

* User inputs text fields, specifying 3 copies of page 2, and 4 copies of page 5.
* User clicks Print button.
* Printer dialog box pops up.
* User selects printer.
* User clicks OK.

After that...

* 3 copies of page 2 printed.
* 4 copies of page 5 printed.

I am including below my current code.  How can I change it to operate as described above?
printButton.addActionListener(new ActionListener() {
	  public void actionPerformed(ActionEvent ae) {
	    int pgToPrint = 13; //This will be read from text field...
	    int numCopy=1; //this will be read from text field...
	    PrinterJob pj = PrinterJob.getPrinterJob();
	    ComponentPrinterFrame cpf = new ComponentPrinterFrame(pp,pgToPrint,arrPg);
	    if (pj.printDialog()) {
	      try { 
    		//Print page numCopy number of times...
    		for(int nCopy=0;nCopy<numCopy;nCopy++){
	      catch (PrinterException pe) {
	        pp.txtProgress.setText("Error: "+pe);

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LarryAndroAuthor Commented:
Well, now that is an elegant answer!  :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.