Create a ok cancel dialog with JOptionPane in Java
Description
The following code shows how to create a ok cancel dialog with JOptionPane.
Example
import java.awt.Component;
/*from w w w. jav a 2 s. c om*/
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] argv) throws Exception {
int i = okcancel("Are your sure ?");
System.out.println("ret : " + i);
}
public static int okcancel(String theMessage) {
int result = JOptionPane.showConfirmDialog((Component) null, theMessage,
"alert", JOptionPane.OK_CANCEL_OPTION);
return result;
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »