[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Printing to a printer

Posted on 1999-11-29
9
Medium Priority
?
244 Views
Last Modified: 2010-04-16
I am using VJ++ (WFC). How can I print some string and variables to a printer? Moreover, how can I specify to print at a particular printer port?
0
Comment
Question by:tracypoon
  • 5
  • 2
  • 2
9 Comments
 

Author Comment

by:tracypoon
ID: 2239857
Thanks!
0
 
LVL 7

Accepted Solution

by:
vladi21 earned 80 total points
ID: 2240331

     If you simply want to print text, then write it to a file and print the
     file. Or open a filename that corresponds to the printer. On Windows,
     that is "LPT1" and the code looks like:

     try {
         FileOutputStream fos = new FileOutputStream("LPT1");
         PrintStream ps = new PrintStream(fos);
                 ps.print("Your string goes here");
                 ps.print("\f");
                 ps.close();
     } catch (Exception e) {
         System.out.println("Exception occurred: " + e);
     }
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:tracypoon
ID: 2242360
Thank you!
But I could not work out with the code, is there any problem with mine?

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.print.*;

public class MyPrint {
            FileOutputStream fos = new FileOutputStream("LPT1");
            PrintStream ps = new PrintStream(fos);
            ps.print("Hello!");
            ps.print("\f");
            ps.close();
}

--------------------------------------
The compilation error is:
MyPrint.java:10: Type expected.
            ps.print("Hello!");
                   ^
1 error

Can you help me again?
0
 
LVL 7

Expert Comment

by:vladi21
ID: 2243255
what about method main?
0
 

Author Comment

by:tracypoon
ID: 2245273
I want to implement a very simple task: when I execute the java program, the printer at a particular port prints the string I wants.
Can you suggest me the main method?
0
 
LVL 5

Expert Comment

by:sgoms
ID: 2245481
modify it to,

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.print.*;

public class MyPrint {
     FileOutputStream fos = new FileOutputStream("LPT1");
     PrintStream ps = new PrintStream(fos);
     public static void main(String args[]){  
                ps.print("Hello!");
                ps.print("\f");
                ps.close();
      }
}

-sgoms
0
 

Author Comment

by:tracypoon
ID: 2245501
I want to implement a very simple task: when I execute the java program, the printer at a particular port prints the string I wants.
Can you suggest me the main method?
0
 

Author Comment

by:tracypoon
ID: 2245532
Thank you very much! I have made it.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

640 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