Where in your code do you see the value of the variable as it is incremented?
Add a println to show its value every time it is incremented.
Is the method being called two times when you think it is being called once?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
What is the value of the page variable every time it is called?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
The API doc for Printable includes this:
For correct printing behaviour, the following points should be observed:
The printing system may request a page index more than once...
... the Printable should expect multiple calls for a page index and that page indexes may be skipped, when page ranges are specified by the client, or by a user through a print dialog.
So the fact that it's called twice may be just how it works.
This all means that the approach of incrementing the page number when print is called is definitely wrong.
You could possibly pass the page number to the constructor of IntroPage and keep that as an attribute of the page, so the page number is created when the page is created and then doesn't change.
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
What do you want to increment?
What does the page variable contain?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Since print can be called any number of times for any page you can't just do the increment in the print method. I would decide the page numbers when creating the pages, as per my previous post.
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
Can you explain the logic of you post. What is it supposed to be doing?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
This is probably a dumb question, but here goes anyway...
Why not just use the page number (index+1) that's passed into print as its third parameter? Isn't that the number that you want to print?
(If not, what EXACTLY is "st" intended to be?)
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
k1=page;
if(k2==k1)
{
k2++;
st=k2;
}
What is the purpose of this code?
What values are the variables k1 and k2 supposed to hold?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Question Answered as of 1 Year Ago by
NormR1,
JamesCherrill
and
Xufyan What happens if the user requests 3 copies of pages 4,5? Your algorithm only works for one specific sequence.
This is my last shot in this topic:
You don't need st or k1 or k2, and anything that increments inside the print method is certain to fail for most print sequences.
All you need for your titleText is page+1;
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30