Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing classes in Graphics

Status
Not open for further replies.

froggy007

Programmer
Mar 8, 2008
1
0
0
Hey,

Have been practising writing classes and having been used to passing parameters through a methd. Now, I am faced with graphics : (

How or what can I pass through in my main for each of the parameters I have defined i.e. Graphics page, int x, int y, int rad, Color color. Obviosuly I know that x, y and rad are intergers but not sure what to pass thru for a graphics page and how to pass thru a color??

Also, I have deliberatley not put a return type in my method but with my new instance in main I am not sure what type to use for the new circle object??

Code:
package Chapter4;

import java.awt.*;
// assumes java.awt.* is imported
public class DrawCircle{
public DrawCircle(){
}
public DrawCircle (Graphics page, int x, int y, int rad, Color color)
{
page.setColor(color);
page.drawOval(x, y, rad, rad);
}
public static void main(String[]args){
DrawCircle circle = new DrawCircle();
newcircle = circle.drawcircle(4,4,4,blue);?????

}
}
 
I'm not sure you can get a Graphics object without actually having something graphic (a window). Maybe this helps.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top