tags:

views:

76

answers:

3

Hello.

I am making a drawing program, using the Graphics 2D objects (lines, rectangles and ovals, namely) by placing them on a panel. With that in mind, I have 2 questions:

1) How can I store the images currently portrayed on the panel as PNG, JPG or similar file onto disk?

2) I have added a drag function. How can I implement a function so that one can see the "outline" of the rectangle, line or oval, before it is actually put onto the canvas (but not placing the outline on the canvas after the mouse button has been released)? I can't see that any of the MouseListener methods can do such a thing.

+1  A: 

1) How can I store the images currently portrayed on the panel as PNG, JPG or similar file onto disk?

You can create a BufferedImage and paint any component onto it. The Screen Image class does this for you.

camickr
A: 

2) How can I implement a function so that one can see the "outline" of the rectangle, line or oval?

In this example, the shape itself may be dragged, rather than its outline, but the draw() method of class Node may be modified as desired. A rectangular outline is used for selection, as on a desktop.

trashgod
A: 

1) ImageIO http://www.java-tips.org/java-se-tips/javax.imageio/how-to-save-a-bufferedimage-to-a-png-file.html

2) Can't think of an answer for 2.

mikek3332002