Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

i m new to java pls help for socket program of printer  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}


Print.java

import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;


public class Print extends Main {

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);
}
}
}
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ned Him,
Welcome to JavaRanch!

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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!