Use a JOptionPane
import java.awt.Component; import javax.swing.JOptionPane; public class Main { public static int yesno(String theMessage) { int result = JOptionPane.showConfirmDialog((Component) null, theMessage, "alert", JOptionPane.YES_NO_OPTION); return result; } public static void main(String args[]) { int i = yesno("Are your sure ?"); System.out.println("ret : " + i); } }