0% found this document useful (0 votes)
10 views4 pages

New Microsoft Word Document

The document contains a Java function for printing a receipt using the PrinterJob class. It defines a PrintObject class that implements the Printable interface to customize the printed content, including order details and customer information. The printing process is initiated through a dialog that checks for available printers before executing the print job.

Uploaded by

zang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

New Microsoft Word Document

The document contains a Java function for printing a receipt using the PrinterJob class. It defines a PrintObject class that implements the Printable interface to customize the printed content, including order details and customer information. The printing process is initiated through a dialog that checks for available printers before executing the print job.

Uploaded by

zang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

// FUNCTION TO CALLS FOR PRINT

boolean f = false;

public void autoPrint(boolean f) {

PrinterJob job = PrinterJob.getPrinterJob();

PageFormat format = job.defaultPage();

Paper paper = new Paper();

double margin = 2;

paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2, paper.getHeight() - margin


* 2);

paper.setSize(3, 4);

job.defaultPage(format);

job.setPrintable(new PrintObject(), format);

boolean printerexists = job.printDialog();

if (printerexists) {

try {

job.print();

} catch (Exception a) {

public class PrintObject implements Printable {

public int print(Graphics g, PageFormat f, int pageIndex) {

if (pageIndex == 0) {

PrintArea(g);

}
return pageIndex;

void PrintArea(Graphics g) {

int x = 150, y = 150;

int i = 0;

Graphics2D g2 = (Graphics2D) g;

g2.setFont(new Font("Lucida COnsole", Font.BOLD, 10));

g2.drawString("AMAKAN NI JEV-JEV", 14, 20);

g2.setFont(new Font("Orator STD", Font.BOLD, 8));

g2.drawString("", 33, 28);

g2.setFont(new Font("Century Gothic", Font.PLAIN, 8));

g2.drawString("Nalibunan, Abuyog, Leyte", 19, 30);

g2.drawString("For orders, contact: 09776958603", 5, 38);

g2.drawString("TIN #: "+" "+TMNo.getText(), 40, 46);

g2.drawString("TN #: "+" "+tinNo.getText(), 30, 55);

g2.drawString("TN.getText()", 100, 134);

g2.drawString("DATE: ", 73, 76);

// g2.drawS00.tring("" + date_Box.getText(), 100, 143);

// g2.drawString("CASHIER: ", 73, 152);

//// g2.drawString(CSHR.getText(), 110, 152);

// g2.drawString("---------------------------------------------", 73, 156);

// g2.setFont(new Font("Arial", Font.PLAIN, 5));

// int x2 = 73, y2 = 160, y3 = 165, count = 0;


// while (i < Table.getRowCount()) {

// if (i == 0) {

// g2.drawString(Table.getValueAt(i, 1).toString(), 80, y2);

// g2.drawString("SRP", 120, y2);

// g2.drawString("SUBT", 146, y2);

// g2.drawString(Table.getValueAt(i, 3).toString(), 100, y3);

// count = count + Integer.parseInt(Table.getValueAt(i, 3).toString());

// g2.drawString("*", 110, y3);

// g2.drawString(Table.getValueAt(i, 2).toString(), 120, y3);

// double sub = Double.parseDouble(Table.getValueAt(i, 2).toString())

// * Double.parseDouble(Table.getValueAt(i, 3).toString());

// g2.drawString(" " + sub, 146, y3);

// i++;

// y2 = y2 + 12;

// y3 = y3 + 12;

// } else {

// g2.drawString(Table.getValueAt(i, 1).toString(), 80, y2);

// g2.drawString(Table.getValueAt(i, 3).toString(), 100, y3);

// count = count + Integer.parseInt(Table.getValueAt(i, 3).toString());

// g2.drawString("*", 110, y3);

// g2.drawString(Table.getValueAt(i, 2).toString(), 120, y3);

// double sub = Double.parseDouble(Table.getValueAt(i, 2).toString())

// * Double.parseDouble(Table.getValueAt(i, 3).toString());

// g2.drawString(" " + sub, 146, y3);

// //g2.drawLine(73, y2+1, 167, y2+1);


// i++;

// y2 = y2 + 12;

// y3 = y3 + 12;

// }

// }

// g2.setFont(new Font("Arial", Font.PLAIN, 6));

// g2.drawString("----------------------------------------------", 73, y3 - 8);

// g2.drawString("Order Count: ", 75, y3 - 3);

// g2.drawString("TOTAL SALES: ", 75, y3 + 4);

// g2.setFont(new Font("Arial", Font.BOLD, 6));

// g2.drawString(payment.amount.getText(), 146, y3 + 4);

// //g2.drawString ("---------------------------------------------", 73, y2+12);

// g2.setFont(new Font("Arial", Font.PLAIN, 6));

// g2.drawString("CASH: ", 75, y3 + 10);

// g2.drawString("" + payment.paid.getText(), 146, y3 + 10);

// g2.drawString("----------------------------------------------", 73, y3 + 13);

// g2.drawString("Change: ", 75, y3 + 18);

// g2.drawString("" + payment.change.getText(), 146, y3 + 18);

// g2.setFont(new Font("Arial", Font.BOLD, 4));

// g2.drawString("****THANKS FOR DROPPING BY****", 88, y3 + 27);

// g2.setFont(new Font("Arial", Font.PLAIN, 4));

// g2.drawString("ORDER TYPE:", 96, y3 + 33);

// g2.drawString("THIS SERVES AS YOUR OFFICIAL RECEIPT", 78, y3 + 45);

// total = 0;

You might also like