This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How does canvas, an exteded JPanel obj have methods getSize(), createImage(size.width, size.height)?  RSS feed

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The below code is from the book Objects First With Java by Michael Kolling and David J. Barnes

Why is the class CanvasPane not included in the Java API?.How does canvas have methods getSize(), createImage(size.width, size.height).canvas is an object of CanvasPane, CanvasPane is an extended object Of Jpanel(a paint() method is added to CanvasPane).Jpanel does not have any of the above mentioned methods




 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Varuna Seneviratna wrote:
Why is the class CanvasPane not included in the Java API?



Do you mean not in the online API documentation? The online JavaDocs are only for the classes that are part of the core Java Runtime (which CanvasPane is not).

Or do you mean why isn't CanvasPane part of the core classes that are part of the Java Runtime Environment? In this case, the API can't have every imaginable type built into it. that is not its purpose. The Java API is designed to provide the building blocks on which other applications can be built. The CanvasPane would be too narrow in its usage to be included in the API.


.How does canvas have methods getSize(), createImage(size.width, size.height).canvas is an object of CanvasPane, CanvasPane is an extended object Of Jpanel(a paint() method is added to CanvasPane).Jpanel does not have any of the above mentioned methods



CanvasPane IS-A javax.swing.JPanel. JPanel IS-A javax.swing.JComponent. JComponent has a getSize() method, which means so does JPanel, and so does CanvasPane.

JComponent IS-A java.awt.Container, and Container IS-A java.awt.Component. Component has a (actually a few) creatImage() methods, which naturally means that any of its subclasses (Container, JComponent, JPanel, and CanvasPane to name a few) inherit these methods.

Take a look at the API for javax.swing.JPanel. Scroll down and you will see a bunch of Methods inherited from... sections which details which methods JPanel has by nature of inheriting them from its parent class even if JPanel doesn't specifically define them itself. As an extension of JPanel, CanvasPane gets them all too.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Luke wrote:CanvasPane IS-A javax.swing.JPanel. JPanel IS-A javax.swing.JContainer. JContainer has a getSize() method, which means so does JPanel, and so does CanvasPane.



I think you meant JComponent here (not JContainer). JComponent does have a getSize() method, but it takes a parameter so is not the one being used here. getSize() without a parameter comes from the java.awt.Component class.
 
Varuna Seneviratna
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve

I can understand most of your answer but I am not able to find JContainer class is it JComponent that you meant as JContainer.In the API which describes JPanel the following is included


java.lang.Object
extended by java.awt.Component
extended by java.awt.Container
extended by javax.swing.JComponent
extended by javax.swing.JPanel




Regards Varuna
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Varuna Seneviratna wrote:I can understand most of your answer but I am not able to find JContainer class is it JComponent that you meant as JContainer.In the API which describes JPanel the following is included



Did you read my correction to Steve's post ?
 
Varuna Seneviratna
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I saw But after I have postedIt took me some time to post going through the API and so on Thank you for the help!



Regards Varuna
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bummer. Sorry for the misleading. I will edit my post so as not to lead others astray. Again, sorry for the mistake, and thanks Joanne for the correction.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!