Re: New to OOP and polymorphism
From: Ryan Stewart (zzanNOtozz_at_gSPAMo.com)
Date: 02/24/04
- Next message: Peter Astbury: "Re: struts javascript validator message problem"
- Previous message: Tux: "Eclipse for Linux: Missing charsets in String to FontSet conversion"
- In reply to: Stephen: "New to OOP and polymorphism"
- Next in thread: Stephen: "Re: New to OOP and polymorphism"
- Reply: Stephen: "Re: New to OOP and polymorphism"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 23 Feb 2004 17:28:35 -0600
"Stephen" <sedelblut@hotmail.com> wrote in message
news:NEr_b.16893$W74.660@newsread1.news.atl.earthlink.net...
> Hi, I am working on a drawing program for class. It consists of a
superclass
> Shape2D where I have subclasses Circle, Square, and Triangle inheriting
from
> Shape2D. I also have a main program that is a JFrame where the shapes are
> drawn. I am trying to use polymorphism and the Shape2D class stores the x
> and y coordinates, and has an abstract method draw(). Here's the problem,
I
> don't know how to use the paint( Graphics g ) method of JFrame to draw the
> shape using the draw method of each shape. Ideally I would like the shapes
> to be drawn like this:
>
> public void paint( Graphics g )
> {
> Shape2D = new Circle( x, y, radius, fillColor );
> Shape2D.draw();
> }
>
> Something like that (I know that is not a real way to do it, it's just the
> best way I can convey my idea ). How do I do this?? Thanks!
>
public void paint( Graphics g )
{
Shape2D aShape = new Circle( x, y, radius, fillColor );
aShape.draw();
}
Like that?
- Next message: Peter Astbury: "Re: struts javascript validator message problem"
- Previous message: Tux: "Eclipse for Linux: Missing charsets in String to FontSet conversion"
- In reply to: Stephen: "New to OOP and polymorphism"
- Next in thread: Stephen: "Re: New to OOP and polymorphism"
- Reply: Stephen: "Re: New to OOP and polymorphism"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|