Java Graphics2D
I'm working on a program using a JFrame.
I have to have the ability to draw boxes and lines anywhere I want. I have methods specifically set up to do this, and they would work except that I can't seem to get the Graphics2D object to work the way I want it.
Here's a simple example of how this problem arises:
***********code**********
public void update(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
g2.draw(new Rectangle2D.Double(5,5,50,50)); // works
}
public void drawLine(int xstart, int ystart, int xend, int yend)
{
Graphics2D g2 = (Graphics2D)getGraphics();
g2.drawLine(xstart, ystart, xend, yend); // doesn't work
update(g2);
}
|