public void saveAs(File f, String ext) throws IOException {
        // check args
        if (f == null || ext == null || ext.length() != 3) {
            throw new IllegalArgumentException("Wrong arguments for saveAs");
        }
        // check if modified
        if (!isModified() && f.equals(currentImageFile)) {
            throw new IllegalStateException("File not modified");
        }
        // args
        int w = currentImage.getIconWidth();
        int h = currentImage.getIconHeight();
        int t = BufferedImage.TYPE_INT_ARGB;
        // JPG have no alpha
        if ("jpg".equals(ext.toLowerCase())) {
            t = BufferedImage.TYPE_INT_RGB;
        }
        // create buffered image from the image icon
        BufferedImage bi = new BufferedImage(w, h, t);
        Graphics2D g2d = (Graphics2D) bi.getGraphics();
        currentImage.paintIcon(null, g2d, 0, 0);
        g2d.dispose();
        // save
        ImageIO.write(bi, ext, f);
        // set flag if not saved as
        if (f.equals(currentImageFile))
        {
            modified = false;
        }
    }