Buscar
Social
Ofertas laborales ES

Foro sobre Java SE > Ayuda con mi código al mandar imprimir

necesito ayuda para lograr unir el print job con el print service para mandar a la ticketera que yo elija y no a la que esta por default.


int V1 = Integer.parseInt(v1.getText());
int V2 = Integer.parseInt(v2.getText());
int V3 = Integer.parseInt(v3.getText());
int V4 = Integer.parseInt(v4.getText());
int V5 = Integer.parseInt(v5.getText());
double V7 = Double.parseDouble(v6.getText());

int C1 = (V1 * 500);
int C2 = (V2 * 200);
int C3 = (V3 * 100);
int C4 = (V4 * 50);
int C5 = (V5 * 20);
double C9 = (V7);
double C6;
C6 = (C1 + C2 + C3 + C4 + C5 + V7);
String V6 = ( "\n Billetes 500> =" +V1 + " + " + C1 + " \n Billetes 200> =" +V2 +" + "+ C2 + " \n Billetes 100> =" +V3 +" + "+
C3 + " \n Billetes 50> =" +V4 +" + "+ C4 + " \n Billetes 20> =" +V5 +" + "+ C5 +" \n Morralla> + "+
C9 +" \n Total> = " + C6 + "\n"+"::::::::::::::::::::::"+"\n"+"======================"+"\n"+"\n"+"\n"+"\n");
System.out.print(V6);

//PrinterJob job = PrinterJob.getPrinterJob();
// job.setPrintable(this);
// boolean impe = job.printDialog();
// if (impe){
//PrintService service = PrintServiceLookup.lookupDefaultPrintService();
//char[] CORTAR_PAPEL=new char[]{0x1B,'m'};
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
DocPrintJob pj = services[0].createPrintJob();
String ss = V6;
byte[] bytes;
bytes=ss.getBytes();
Doc doc=new SimpleDoc(bytes,flavor,null);
try {
pj.print(doc,null);
}
catch (PrintException e) {
System.out.println("Error al imprimir: "+e.getMessage());
}
//
v1.setText ("0");
v2.setText ("0");
v3.setText ("0");
v4.setText ("0");
v5.setText ("0");
v6.setText ("0");
}

public String CortarHoja() {
return (char)27+ "m";
}
public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new tuto1().setVisible(true);
}
});
}

junio 11, 2016 | Unregistered Commentermanuex

public DocPrintJob getPrinterJob(String serviceName) {
DocPrintJob printerJob = null;
for (PrintService printService : PrintServiceLookup.lookupPrintServices(null, null)) {
if (printService.getName().equals(serviceName)) {
printerJob = printService.createPrintJob();
break;
}
}
return printerJob;
}

junio 12, 2016 | Registered Commenterchoces

Amigo muchas gracias me ayudaste mucho mil gracias

junio 14, 2016 | Registered Commentermanuex