Jump to content

  • Log In with Google      Sign In   
  • Create Account

[java] Printing Graphics


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 dog135   Members   -  Reputation: 122

Like
Likes
Like

Posted 15 October 2000 - 03:42 AM

I''ve searched all my books and came up with nothing on this. How can I print graphics from java? All I want to do it print boxes around pieces of text, but according to my books, I can only print text. Does anyone know, perhaps, a workaround for this? I was thinking about exporting the information to a file and writing a program in C++ to do the printing, but that''s not very conveniant to the user. E:cb woof!

Sponsor:

#2 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 October 2000 - 03:35 AM

I don''t know how you are trying to print your document, so I can''t be of much help. Here is a link to the Javasoft Printing topics page. Maybe one of these references has your answer.

http://java.sun.com/printing/index.html

#3 dog135   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 October 2000 - 10:22 AM

I found some code that looks like what I need. However, I still get an error. The link I found is at: http://molsun.ophth.uiowa.edu/~tscheetz/java/awt/print-ex1.html.

Here it is:

public void print_hello()
{
PrintJob pjob;
Properties p = new Properties();
Graphics pgraphics;
String hello = new String("Hello World!");
String name = new String("Print Job Name");
int x, y;

pjob = getToolkit().getPrintJob(this, name, props);
if(pjob != null) {
pgraphics = pjob.getGraphics();
if(pgraphics != null) {
pgraphics.setFont(new Font("Serif",Font.PLAIN,14));
x = 50;
y = 50;
pgraphics.drawString(hello,x,y);
pgraphics.dispose();
}
pjob.end();
}

}

Now, most of this works. The only place I'm getting an error now, is at the "getPrintJob(this, name, props)" method. It can't convert "this" to a frame. I have the code inside of a Java Applet. Does it need to be inside a Java Application?

What I'm trying to do is print graphics. (a rectangle in this case) This method above allows that.

E:cb woof!

Edited by - Dog135 on October 16, 2000 5:24:39 PM




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS