Solved

how to print?

Posted on 2002-03-11
7
202 Views
Last Modified: 2006-11-17
Hi all,

In my program  I wanted to print the customer details stored in buffer . what class library I need to import & how am I to go about it ?
can anyone help me out in solving this problem.

Thanks
shanth
0
Comment
Question by:shanth_77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 6855902
try this code:
java.awt.Frame frame = new java.awt.Frame("Title");
java.util.Properties properties = new java.util.Properties();
//create a print jobjava.awt.PrintJob pj = java.awt.Toolkit.getDefaultToolkit().getPrintJob(frame, "jobtitle", properties);
//use the print job graphics object to draw the printings
pj.getGraphics().drawString("This is a test!", 10, 10);
pj.end();

all you need is the java.awt package ...
0
 

Author Comment

by:shanth_77
ID: 6857499
hi venci,
I tried with ur code as below but it generates an error with class not found for jobjava.awt.PrintJob
Please help me out proceed further.
It would be an good attempt if U can help me to issue the print command from dos-prompt.

import java.awt.*;
import java.util.*;
public class Prin{
public Prin()
{
java.awt.Frame frame = new java.awt.Frame("Title");
java.util.Properties properties = new java.util.Properties();
jobjava.awt.PrintJob pj = java.awt.Toolkit.getDefaultToolkit().getPrintJob(frame, "jobtitle", properties);
//use the print job graphics object to draw the printings

pj.getGraphics().drawString("This is a test!", 10, 10);
pj.end();
}

public static void main(String args[])
{
new Prin();
}

Thanx in advance
shanth_77
0
 
LVL 9

Expert Comment

by:Venci75
ID: 6859824
Sorry - the correct line is:
java.awt.PrintJob pj = java.awt.Toolkit.getDefaultToolkit().getPrintJob(frame, "jobtitle", properties);

the "job" prefix should be part of the comment
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:shanth_77
ID: 6863511
Hi Venci,
  I tried UR coding, its with no errors and complied fine with the print dialog box shown.But the content is not written to the frame.
The drawString does not work.Is it possible to direct the dos based application to direct to printing?
please help me out!!!!!!!!!!

thanx in advance.
shanth_77
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 30 total points
ID: 6863777
Hi shanth_77,

in the line:
pj.getGraphics().drawString("This is a test!", 10, 10);
the coordinates (10, 10) are not in the printable area. Sorry for this, but I haven't tried it.
I tried now with (200, 200) coordinates:
pj.getGraphics().drawString("This is a test!", 200, 200);
and the text was printed.

Regarding the DOS printing - yes it is possible, but I don't recomend it to you. The way is to redirect the output of your application to the printer:
my_app.bat > LPT1
or
type my_file.txt > LPT1
0
 

Author Comment

by:shanth_77
ID: 6866782
Venci,
 Thanx for ur due help over the above.
But iam slightly confused with dos mode print of specifying the file to printer because i store my contents in bufferreader and not in a file.
can i still print out?

shanth_77
0
 

Author Comment

by:shanth_77
ID: 6866895
venci,
  I tried with ur advice as above, but when i show the frame there is no content as This is Test written.
Its not displayed.

pj.getGraphics().drawString("This is Test",100,100);
frame.show();
pj.end();

shanth_77
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 136
Adding multiple JVM environments to RedHat 6 7 82
ejb entity bean example issue 2 43
Glassfish admin console not working 1 88
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question