File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Graphics2D compiler error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Graphics2D compiler error " Watch "Graphics2D compiler error " New topic
Author

Graphics2D compiler error

Duane Riech
Ranch Hand

Joined: Feb 27, 2003
Posts: 52
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... */
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8866
    
    8

Originally posted by Duane Riech:

/*
* 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.
*/

Your comment before the declaration of g2 isn't terminated. The commented-out area then extends to the next terminator, after the next comment.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Duane Riech
Ranch Hand

Joined: Feb 27, 2003
Posts: 52
You're right....
Stupid mistake...
My apology....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphics2D compiler error