In my code( below ), I used Vectors which store the line point to resume the lines drawed before. But when filling or storing the color of the line, it will be hard to realize. Maybe using BufferedImage can solve it, but how to use?
I find a way to solve it now. In the constructor create a BufferedImage the same size as the JPanel, then use a Graphics2D object created by the image to paint the background of the BufferedImage to white. If to store the imformation to the image, using the Graphics2D obejct of the image to draw immediately. Then paint the image in the paint() or paintComponent().
<----initialize a BufferedImage object--> BufferedImage infoStored = new BufferedImage( int width, int height, BufferedImage.TYPE_INT_RGB ); Graphics2D g2d = infoStored.createImage(); g2d.setBackground( Color.WHITE ); g2d.clearRect( 0, 0, width, height ); //paint to white
<-- paint image --> g.drawImage( infoStored, 0, 0, this ); [ April 08, 2008: Message edited by: Wei Chen ]
You obviously missed the naming policy when you logged in: first name-space-last name. Please correct your displayed name to match.
No, we can't show you an example of what would work; you aren't going to learn anything from that. Rather, you show us what you have got and tell us what you think is going wrong. Please post what you have got, once you get the name thing sorted out.