New to OOP and polymorphism

From: Stephen (sedelblut_at_hotmail.com)
Date: 02/23/04


Date: Mon, 23 Feb 2004 18:30:05 GMT

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!



Relevant Pages

  • 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 ... I also have a main program that is a JFrame where the shapes are ... > don't know how to use the paint(Graphics g) method of JFrame to draw the ...
    (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)
  • Re: New to OOP and polymorphism
    ... > draw method class to make it draw on the JFrame client program using the ... The Circle class is like ... your Shape2D class. ...
    (comp.lang.java)