
Untitled
By: a guest on
Jul 10th, 2012 | syntax:
Java | size: 0.94 KB | hits: 14 | expires: Never
public MyDialogs {
public static final int NEGATIVE = 0;
public static final int POSITIVE = 1;
private static final int UNSET = -1;
private static Object sem = new Object();
public static int showConfirmDialog(String message) {
JFrame frame = new JFrame("Continue?");
JButton ok = new JButton("Ok");
JButton cancel = new JButton("Cancel");
int retValue = UNSET;
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
retValue = POSITIVE;
sem.notify();
}
}
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
retValue = NEGATIVE;
sem.notify();
}
}
frame.add(new JLable(message));
frame.add(ok);
frame.add(cancel);
frame.setVisible(true);
while(retValue == UNSET) {
sem.wait();
}
return retValue;
}
}