Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing an object

 
Vani Shastri
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am very new to the topic related to I/O operations.
I would like to know if there is any way of printing an object. At the printing stage, is it possible to allign the fields of the object?

Looking forward for guidance.

Thank you.
 
Vani Shastri
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a little closer to the above mentioned problem.
I am able to print graphical objects on the desired location (by providing the co-ordinates). But, I am not able to allocate a location to print the object "o". Is there any way to do it?






Thanks
 
Joe Ess
Bartender
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you attempting to print an object to a printer (which is what java.awt.print is for) or are you just trying to write the object's values out to the screen (which is what System.out.println() is for)?
 
Vani Shastri
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yea, i shouldnt have used System.out.println();
My requirement is to print an object at the printer directly.
Is there a way? If there is, please guide me.

Thanks.
 
Joe Ess
Bartender
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to send an object to a printer directly. How would a printer know what to print? There's a chapter on the printing API in the Java Tutorial that would be a good place to start.
 
Vani Shastri
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for tht API. But I guess objects are printable. For eg in the above mentioned code, the object "rect" is printed. My understanding was we have to import awt.print and implement printable. I agree that the user cannot give acommand to print the object directly. That job is done by the Printable object (If I have understood it right).

PrinterJob job = PrinterJob.getPrinterJob();

job.setPrintable(new PrintObject());

Do correct me if I am wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic