• 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

Help with graphics Object

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
…and the Java Language Specification about narrowing primitive conversions. But it may be difficult to read.
 
reply
    Bookmark Topic Watch Topic
  • New Topic