Thread: Java Graphics2D
View Single Post
Old 09-22-2004, 04:07 PM   #1 (permalink)
insidious_machinae
Psycho
 
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);
}
insidious_machinae is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73