import javax.swing.JFrame; import javax.swing.JOptionPane; public class Main { public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); String message = "message"; String text = JOptionPane.showInputDialog(frame, message); if (text == null) { // User clicked cancel } } }