Computer Science Canada Paint in a separate class? |
Author: | Fozmik [ Thu Jan 08, 2009 1:58 am ] | ||
Post subject: | Paint in a separate class? | ||
I'm trying to create a class which paints a square using the method paint (Graphics g). In another class, in my main method, I create an AWT frame and an object of the square-painting class, but the square does not appear on my frame. How can I make something like this work?
Sorry if this is a dumb question. |
Author: | wtd [ Thu Jan 08, 2009 3:38 am ] |
Post subject: | Re: Paint in a separate class? |
Well, have you added the Square object to your Frame? You could use the Frame class' [url=http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Container.html#add(java.awt.Component)]add[/url] method, but the signature for that requires that you add a java.awt.Component object. Your Square object is not a Component, so it won't work there. Do you understand the is a relationship in object-oriented programming? |
Author: | Fozmik [ Thu Jan 08, 2009 3:30 pm ] | ||||
Post subject: | Re: Paint in a separate class? | ||||
I tried adding the Square to Frame with,
and making the Square a component with,
It is still not appearing though *edit* It works now, thanks |