Home arrow static arrow Java Programming [Archive] - print called twice
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - print called twice
This topic has 4 replies on 1 page.

Posts:8
Registered: 6/16/04
print called twice  
Jul 30, 2004 10:32 AM



 
Hello: I am writing a small app to print out prescriptions our Docs wirte out for patients. I have developed a class that implements the printable interface. This class is responsible for printing one page of prescriptions with up to 6 on one page.

My problem is that somehow this class gets called twice during the print . Here is small sinpet:

// Determine number of pages to print. Each page can have no more than 6 prescriptions.
// pscriptArray holds prescription data collected from GUI input.
int drugsPrescribed = 0;
int numPages = 0;
for(int i = 0; i < 35; i++) {
if(pscriptArray.isPrescribed()) {
drugsPrescribed++;
}
}
// Round up to next highest integer for last page
numPages = (int) Math.ceil(drugsPrescribed / 6.0);

for (int j = 0; j < numPages; j++) {
System.out.println("loop: " + (j+1));
PscriptPage page = new PscriptPage();
book.append(page, documentPageFormat);
}

// Print the book using the specified flavor
Doc doc = new SimpleDoc(book, flavor, das);
job.print(doc, pras);

Given the above, I have confirmed that the print method in the PscriptPage class gets called twice when it should only get called once. Removing FOR statement causes same behavior confirming it is anot a loop issue.

The method I used to determine the extra loop is to simply use a system print statement inside the print method. THis confirmed it was running twice.

So why should this happen???

Thanks, Chris.

 

Posts:6,750
Registered: 1/25/04
Re: print called twice  
Jul 30, 2004 10:35 AM (reply 1 of 4)



 
Please repost with code tags.
 

Posts:403
Registered: 9/4/03
Re: print called twice  
Jul 30, 2004 11:39 AM (reply 2 of 4)



 
Maybe try printing out numPages before the for() loop so you can see how many pages you have.
 

Posts:8
Registered: 6/16/04
Re: print called twice  
Aug 2, 2004 5:50 AM (reply 3 of 4)



 
unsavory: I now believe the problem is with "peeking" of the java print routine which looks at teh print job before actually printing to determine the best print method to use. This causes my loop to increment once. What I really need is a way to pass an array to the print jobas a parameter. Can you overload the print method in a class that implements printable???

Chris
 

Posts:6,750
Registered: 1/25/04
Re: print called twice  
Aug 2, 2004 8:21 AM (reply 4 of 4)



 
Sure, but anything operating on a reference of type Printable will never call the overloaded method.
 
This topic has 4 replies on 1 page.