Re: New to OOP and polymorphism

From: Ryan Stewart (zzanNOtozz_at_gSPAMo.com)
Date: 02/24/04


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?



Relevant Pages

  • New to OOP and polymorphism
    ... I am working on a drawing program for class. ... Shape2D where I have subclasses Circle, Square, and Triangle inheriting from ... I also have a main program that is a JFrame where the shapes are ... and has an abstract method draw(). ...
    (comp.lang.java)
  • Re: New to OOP and polymorphism
    ... I am working on a drawing program for class. ... > Shape2D where I have subclasses Circle, Square, and Triangle inheriting from ... > don't know how to use the paint(Graphics g) method of JFrame to draw the ... I think you will have to write a JPanel extended class or JLabel ...
    (comp.lang.java)