import java.awt.print.*;
import java.awt.*;
public class Test implements Printable {
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex){
if (pageIndex == 0) {
int x = (int)(pageFormat.getWidth() / 4);
int y = (int)(pageFormat.getHeight() / 4);
int w = (int)(pageFormat.getWidth() / 2);
int h = (int)(pageFormat.getHeight() / 2);
graphics.setColor(Color.RED);
graphics.drawOval(x, y, w, h);
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
public static void main(String args[]) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new Test());
if (job.printDialog()) {
try {
job.print();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}