I'm studying up on the Printable interface and am trying to use an example from a book. I'm getting compile errors on the variable g2, (Marked in code).
Since class Graphics2D is abstract and I'm subclassing from parent Graphics g, I don't understand what the compiler wants.
This is just part of the code containing the class.
Thanks...
PrinterClass.java:187: cannot resolve symbol
symbol : variable g2
location: class Project.PrinterClass.paintContent
int y = g2.getFont().getSize() * 5 / 2;
^
PrinterClass.java:189: cannot resolve symbol
symbol : variable g2
location: class Project.PrinterClass.paintContent
g2.translate( xo + x, yo + y );
^
PrinterClass.java:191: cannot resolve symbol
symbol : variable g2
location: class Project.PrinterClass.paintContent
AffineTransform old = g2.getTransform();
^
PrinterClass.java:193: cannot resolve symbol
symbol : variable g2
location: class Project.PrinterClass.paintContent
g2.drawString( RecipeTitle, 0, 0 );
^
4 errors
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.Graphics2D;
import java.awt.print.*;
..
..
..
..
class paintContent implements Printable {
public int print( Graphics g, PageFormat pf, int pageIndex ) {
/*
* Construct a new Graphics2D object.
*
Graphics2D g2 = (Graphics2D) g;
/*
* Get the width, in 1/72nds of an inch, of the imageable area of the page.
*/
double width = pf.getImageableWidth();
/*
* Get the height, in 1/72nds of an inch, of the imageable area of the page.
*/
double height = pf.getImageableHeight();
/*
* Get the x coordinate of the upper left point of the imageable area of
* the class Paper object associated with this PageFormat.
*/
int xo = (int) pf.getImageableX();
/*
* Get the y coordinate of the upper left point of the imageable area of
* the class Paper object associated with this PageFormat.
*/
int yo = (int) pf.getImageableY();
String Title = " Title : Gone with the Wind";
int x = Title.length() / 10;
Error-> int y = g2.getFont().getSize() * 5 / 2;
Error-> g2.translate( xo + x, yo + y );
Error-> AffineTransform old = g2.getTransform();
Error-> g2.drawString( Title, 0, 0 );
return Printable.PAGE_EXISTS;
} /* ...end of method print()... */
} /* ...end of class declaration paintContent... */