Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to print?

Posted on 2002-03-11
7
Medium Priority
?
210 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 120 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

721 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