• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with graphics Object  RSS feed

 
Andy Richard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just read that in order to get the functionality that Graphics2d provide, but not the Graphics class,
we cascade the graphics2d as follows...

now,
afaik, we cascade the .bigger values into the smaller ones,
for example..

if we replace int with float ( or vice-versa ) then, that wouldn't work!
then how is it possible here with Graphics and Graphics2d ??
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's called casting, not cascading.

It's possible with Graphics2D and Graphics because Graphics2D is a subclass of class Graphics, and the object that g refers to is actually a Graphics2D object (even though the type of the variable is Graphics).

Casting is explained in The Java Tutorials on the page about inheritance.
 
Campbell Ritchie
Marshal
Posts: 56520
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
…and the Java Language Specification about narrowing primitive conversions. But it may be difficult to read.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!