It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes How does canvas, an exteded JPanel obj have methods getSize(), createImage(size.width, size.height)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How does canvas, an exteded JPanel obj have methods getSize(), createImage(size.width, size.height)?" Watch "How does canvas, an exteded JPanel obj have methods getSize(), createImage(size.width, size.height)?" New topic
Author

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

Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
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






Varuna Seneviratna
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3534
    
  15
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.


Joanne
Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
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



Regards Varuna
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3534
    
  15
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

Joined: Jan 15, 2007
Posts: 167
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does canvas, an exteded JPanel obj have methods getSize(), createImage(size.width, size.height)?