i m new to java pls help for socket program of printer
ned him
Greenhorn
Joined: Aug 06, 2007
Posts: 7
posted
0
my program is given below but i need for ' in a network 3 computers are connected with ipaddress 192.168.0.1, 192.168.0.2, 192.168.0.3. Each computer having a printer. Now i am run a program on computer1(192.168.0.1) at that time computer3's(192.168.0.3) printer is activate and gives printout'. what is the program
plese help me...
Main.java
public class Main
{ public static String text2print; public static void main (String [] args) { text2print="This rolls out the printer......"; Print dezetekst=new Print(); System.exit (0); } }
private final static int POINTS_PER_INCH = 12; //private String text2print;
public Print () { //--- Create a new PrinterJob object PrinterJob printJob = PrinterJob.getPrinterJob (); //--- Create a new book to add pages to Book book = new Book (); //--- Add the cover page using the default page format for this print job book.append (new IntroPage (), printJob.defaultPage ()); //--- Tell the printJob to use the book as the pageable object printJob.setPageable (book); try { printJob.print(); } catch (Exception PrintException) { PrintException.printStackTrace(); } } public void setPrint(String printmij) { text2print=printmij; }
private class IntroPage implements Printable{
public int print (Graphics g, PageFormat pageFormat, int page) {
//--- Create the Graphics2D object Graphics2D g2d = (Graphics2D) g; //--- Translate the origin to 0,0 for the top left corner g2d.translate (pageFormat.getImageableX (), pageFormat.getImageableY ()); //--- Set the default drawing color to black g2d.setPaint (Color.black); //--- Print the title String titleText = text2print; Font titleFont = new Font ("arial", Font.BOLD, 12); g2d.setFont (titleFont); //--- Compute the horizontal center of the page FontMetrics fontMetrics = g2d.getFontMetrics (); double titleY = 3 * POINTS_PER_INCH; double titleX =0; g2d.drawString (titleText, (int) titleX, (int) titleY); return (PAGE_EXISTS); } } }
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35223
7
posted
0
"PrinterJob.getPrinterJob()" returns the default printer. If you want to select which printer to use, use PrinterJob.lookupPrintServices(). It returns a list of all available printers, from which you can choose the correct one.
In an effort to help you get the most from our forums, we've compiled a list of tips for asking questions here. You can find the list in our FAQ section here. In particular please see: UseAMeaningfulSubjectLine UseCodeTags UseRealWords
Abbreviations such as "u" or "ur" in place of "you" and "you are" or "you're" confound language translation software making it hard for our non-English speaking members to read your posts. "plz" is not a word in the English language.
Again, welcome to JavaRanch and good luck with your question. -Ben