import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import static java.awt.print.Printable.NO_SUCH_PAGE;
import static java.awt.print.Printable.PAGE_EXISTS;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class frmPri2 extends javax.swing.JFrame implements Printable {
public frmPri2() {
initComponents();
}
private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
try {
job.print();
} catch (PrinterException e) {
e.printStackTrace();
}
}
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) g;
Image img1;
ImageIcon icon = new ImageIcon("barcode2.gif");
img1 = icon.getImage();
g.drawString("minuvaHard10 corp.", 100, 100);
g.drawString("Simulacion de Ticket", 100, 130);
g.drawImage(img1, 200, 150,null);
return PAGE_EXISTS;
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new frmPri2().setVisible(true);
}
});
}
}
minuvasoft10@gmail.com Programador de Proyectos Software.