Computer Science Canada

Quick question on Graphics

Author:  xHoly-Divinity [ Sat Apr 01, 2006 3:39 pm ]
Post subject:  Quick question on Graphics

code:

public void draw (int x, int y, Graphics g)
    {
    }


Suppose I did not want to include the Graphics as part of the call method, how would i incorporate it in the body of the method so that I could still draw things using the graphics.

So lets say

code:

public void draw (int x, int y)
    {
    g.fillOval (4, 4, 4, 4);
    }


How would I go about achieving that? I would have to call graphics somewhere within the method, just not 100% sure of the syntax and it is driving me crazy!! :S. Thanks

Author:  McKenzie [ Sat Apr 01, 2006 4:49 pm ]
Post subject: 

Assuming it has a legitimate Graphics context (Applet, Frame ...) try
code:
Graphics g = this.getGraphics ();


: