Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Component;
import java.io.File;
import javax.swing.JOptionPane;

public class Main {
    /**
     * Show a dialog that asks the user if a certain file should be overwritten. Nothing
     * will happen if the given file does not exist.
     * @param parent
     * @param file File to be overwritten.
     * @return {@code true} if the user confirms or if the file does not exist.
     */
    public static boolean confirmFileWriting(Component parent, File file) {
        if (!file.exists())
            return true;

        return JOptionPane.showConfirmDialog(parent,
                "The file '" + file.getName() + "' does already exist. Overwrite?", "Confirm",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
    }
}