• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Printing: Can�t use draw drawString(...) in a loop!?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I�m writting a class to print simple Text. But in the print-Methode of the Interface Printable I can�t use a loop to put my Text on my page.
I have no idea why this code doesn�t work:

In advance, thanks a lot!
Regards, Dirk
[ April 17, 2002: Message edited by: Dirk Mohr ]
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say it doesn't work, can you please give a little more detail about what is actually happening?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bruder,
Considering:

It would seem to me that the first question to resolve is: Is the while loop ever entered - does (zeile < text.length) ever test true? Are you certain that the while loop is indeed entered?
Second: Does (text[zeile]!= null) ever test true for any of the components in text?
Otherwise, I don't see anything about your for-loop structure that could be behaving other than as expected.
Viel Glueck.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm possibly not exploring anything less than obvious, but a quick and easy test to answer the above two questions could include something such as:

Good Luck.
 
Dirk Mohr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, to be more detailed:
The loop is not the problem, pg.drawString(text[zeile], x, y) is executed for every element of text[] that is not null. If I use

I get right that text on my screen I�d like to see on the printed page (plus the coordinates). That is:


Hallo! x:71 y:300
Dies ist ein Test x:71 y:332
Noch `ne Zeile! x:71 y:348


But on the printed page I only see the text that is generated by the (first) sequence of drawString(...) commands. This is realy mysterious, isn�t it?
Hope you can help me!
Regards, Dirk
[ April 18, 2002: Message edited by: Dirk Mohr ]
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OH, one important fact just popped up in my brain....the
print(Graphics pg, PageFormat pformat, int pageIndex)
method in the Printable interface actually gets called multiple times for the exact same page. It's important that your internal state be exactly consistent between invokation.
What is probably happening is that your print() method works correctly the first time it's called, and correctly runs your loop. But after this point, the ziele variable gets incremented passed the length of the text array, so the second time it's called, the while loop is not exectuted.
This seems to require a design change of your algorithm, because basically, this print() method is NOT reentrant.
 
Dirk Mohr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Year!
Rob, you hit the spot!
Thanks a lot, Dirk
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic