Solved

how to print?

Posted on 2002-03-11
7
194 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 72
array220 challenge 8 48
java set up 1 48
wordcount challenge 11 78
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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:
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now