• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Graphics2D compiler error

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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... */
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Duane Riech
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right....
Stupid mistake...
My apology....
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic