protected void save() {
    try {
      File fFile = new File("test.jpeg");
      this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
      JFileChooser fc = new JFileChooser();
      // Start in current directory
      fc.setCurrentDirectory(new File("."));
      // Set to a default name for save.
      fc.setSelectedFile(fFile);
      // Open chooser dialog
      int result = fc.showSaveDialog(this);
      if (result == JFileChooser.CANCEL_OPTION) {
      } else if (result == JFileChooser.APPROVE_OPTION) {
          fFile = fc.getSelectedFile();
          if (fFile.exists()) {
              int response = JOptionPane.showConfirmDialog(null,
                      "Overwrite existing file?", "Confirm Overwrite",
                      JOptionPane.OK_CANCEL_OPTION,
                      JOptionPane.QUESTION_MESSAGE);
              if (response == JOptionPane.CANCEL_OPTION) {
              }
          }
          // save buffered image
          Image img = createImage(getWidth(), getHeight());
          Graphics g = img.getGraphics();
          paint(g);
          ImageIO.write(toBufferedImage(img), "jpeg", fFile);
          JOptionPane.showMessageDialog(null, "Image saved to " + fFile.toString());
          g.dispose();
        }
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } 
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }