This code my code, but it does not save the image just blank page. PLEASE HELP
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
class SaveButtonAction implements ActionListener {
DataContainer dcRef = null;
ActionContainer ac = null;
DrawingCanvas drawingPanel = null;
String cmd = null;
JFrame f = new JFrame();
SaveButtonAction(DataContainer dc, ActionContainer ac, DrawingCanvas drawingPanel) {
dcRef = dc;
this.ac = ac;
this.drawingPanel = drawingPanel;
}
public void actionPerformed(ActionEvent e) {
System.out.println("[savebutton] pushed");
//sets up the action similar to plot
drawingPanel.plotPie(cmd); // plot pie charts
//set up graphics 2d
try {
BufferedImage image =
new BufferedImage( 120, 120, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = image.createGraphics();
f.paint( graphics2D );
graphics2D.dispose();
ImageIO.write(image, "png", new File("AA.png"));
} catch (Exception ex) {
ex.printStackTrace();
}
//call the drawpanel.repaint();
drawingPanel.repaint(); // draw
}
}
public class SaveButton extends GButton {
SaveButton(String name, DataContainer dcRef, ActionContainer ac, DrawingCanvas drawingPanel) {
super(name, dcRef);
SaveButtonAction action = new SaveButtonAction(dcRef, ac, drawingPanel);
addActionListener(action);
}
}