New to OOP and polymorphism
From: Stephen (sedelblut_at_hotmail.com)
Date: 02/23/04
- Next message: pmdanger: "Best java development tool"
- Previous message: Dr. Mercury: "Re: Anyone for a small Java challenge?"
- Next in thread: Ryan Stewart: "Re: New to OOP and polymorphism"
- Reply: Ryan Stewart: "Re: New to OOP and polymorphism"
- Reply: hiwa: "Re: New to OOP and polymorphism"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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!
- Next message: pmdanger: "Best java development tool"
- Previous message: Dr. Mercury: "Re: Anyone for a small Java challenge?"
- Next in thread: Ryan Stewart: "Re: New to OOP and polymorphism"
- Reply: Ryan Stewart: "Re: New to OOP and polymorphism"
- Reply: hiwa: "Re: New to OOP and polymorphism"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|