BOA TARDE PESSOAL
ESTOU CRIANDO UM SISTEMA DE PONTO ELETRÔNICO POREM EU PRECISAVA DE ALGUM COMANDO QUE DEPOIS QUE O USUÁRIO PASSAR O CRACHÁ VENHA IMPRIMIR UM PAPEL INFORMANDO QUAL O HORARIA E O DIA ATUAL COM O NOME DO FUNC. MAS ISSO TEM QUE SER DIRETO SEM TER QUE O USUÁRIO ESCOLHA A IMPRESSORA
A CLASSE QUE EU USO PARA IMPRIMIR É ESSA.
package barras;
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
public class PrintUtilities implements Printable {
private Component componentToBePrinted;
public static void printComponent(Component c) {
new PrintUtilities(c).print();
}
public PrintUtilities(Component componentToBePrinted) {
this.componentToBePrinted = componentToBePrinted;
}
public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
try {
printJob.print();
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
}
}
public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
}
public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}
E COMANDO QUE EU USO PARA IMPRIMIR É ESSE.
PrintUtilities.printComponent(jPanelVerso);
ESTE COMANDO ESTOU USANDO PARA IMPRIMIR EM OUTRO OCASIÃO QUE O USUARIO PODE ESCOLHER QUAL IMPRESSORA MAS TEM A OCASIÃO CITADA ACIMA QUE O USUÁRIO NÃO VAI PODER ESCOLHER NADA.
SERA QUE ALGUÉM PODE ME AJUDAR.