Solved

how to print?

Posted on 2002-03-11
7
206 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

628 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