printing
sry if this is the wrong forum
I am trying to print from an applet
when I execute the print method in my class the implements Printable, all ti prints is a blank page
here is the code:
//
// printer.java
// image tracer
//
// Created by Erik Schmidt on 8/18/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
import java.awt.*;
import java.awt.print.*;
publicclass printerimplements Printable{
private Graphics p;
public printer(Graphics g){
p=g;
}
public printer(){
//do nothing
}
void printPage(){
PrinterJob printerJob=PrinterJob.getPrinterJob();
Book book=new Book();
book.append(new printer(),new PageFormat());
printerJob.setPageable(book);
try{
printerJob.print();
}catch(Exception ex){
//do nothing
}
}
publicint print(Graphics g,PageFormat format,int pageIndex){
g=p.create();
return Printable.PAGE_EXISTS;
}
}
//
// image_tracer.java
// image tracer
//
// Created by Erik Schmidt on 8/17/06.
// Copyright (c) 2006 __MyCompanyName__. All rights reserved.
// A simple Java applet
//
//import statements
//for graphics
import java.awt.*;
//for applet declaration
import java.applet.*;
//for event management, eventaully, for printing and buttons
import java.awt.event.*;
//for the Image class
import java.awt.Image;
//for the URL class
import java.net.*;
//for the ImageObserver class
import java.awt.image.ImageObserver;
//for ArrayList
import java.util.*;
//for component class
import java.awt.Component;
//declares class and declares class to be an Applet
publicclass image_tracerextends Applet{
//contains the face image
private Image image;
//Image observer for resizing the applet
private ImageObserver ob;
//integer values for drawing the ovals
int first,second;
//graphics context eventaully for printing
Graphics p;
//ArrayLists to save the painted ovals
ArrayList first_list,second_list;
//component for printing
Component comp;
//Printer job
printer pr;
//Image observer for the blank image
ImageObserver ob2;
//Image for the blank drawing slate
Image blank;
publicvoid init(){
try{
//blank=getImage(new URL("http://erik-schmidt90s-ibook-g4.local/~erikschmidt90/blank.jpg"));
image=getImage(new URL("http://erik-schmidt90s-ibook-g4.local/~erikschmidt90/face.jpg"));
}catch(MalformedURLException ex){
//do nothing
}
setLayout(null);
first_list=new ArrayList();
second_list=new ArrayList();
Integer i=new Integer(-20);
Integer j=new Integer(-20);
first_list.add(i);
second_list.add(j);
first=0;
second=0;
blank=createImage(500,500);
p=blank.getGraphics();
}
publicvoid paint(Graphics g){
//resize(image.getWidth(ob),image.getHeight(ob));
g.drawImage(image,0,0,null,ob);
g.setColor(Color.black);
p.setColor(Color.black);
g.drawRect(image.getWidth(ob)+20,image.getHeight(ob)+20,50,50);
g.drawString("Print",image.getWidth(ob)+30,image.getHeight(ob)+50);
resize(image.getWidth(ob)+70,image.getHeight(ob)+70);
for(int i=0;i<first_list.size();i++){
Object obj=first_list.get(i);
first=((Integer)obj).intValue();
obj=second_list.get(i);
second=((Integer)obj).intValue();
g.fillOval(first,second,20,20);
p.fillOval(first,second,20,20);
}
}
publicboolean mouseMove(Event evt,int x,int y){
Integer i=new Integer(x);
Integer j=new Integer(y);
if(x><=image.getWidth(ob) && y<=image.getHeight(ob)){
first_list.add(i);
second_list.add(j);
}
repaint();
returntrue;
}
publicboolean mouseDown(Event evt,int x,int y){
if(x>=image.getWidth(ob)+20 && y>=image.getHeight(ob)+20 && x<=image.getWidth(ob)+70 && y<=image.getHeight(ob)+70){
pr=new printer(p);
pr.printPage();
}
returntrue;
}
}
TIA

