Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 10th, 2012  |  syntax: Java  |  size: 0.94 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public MyDialogs {
  2.   public static final int NEGATIVE = 0;
  3.   public static final int POSITIVE = 1;
  4.   private static final int UNSET = -1;
  5.  
  6.   private static Object sem = new Object();
  7.  
  8.   public static int showConfirmDialog(String message) {
  9.     JFrame frame = new JFrame("Continue?");
  10.     JButton ok = new JButton("Ok");
  11.     JButton cancel = new JButton("Cancel");
  12.  
  13.     int retValue = UNSET;
  14.  
  15.     ok.addActionListener(new ActionListener() {
  16.       public void actionPerformed(ActionEvent arg0) {
  17.         retValue = POSITIVE;
  18.         sem.notify();
  19.       }
  20.     }
  21.  
  22.     cancel.addActionListener(new ActionListener() {
  23.       public void actionPerformed(ActionEvent arg0) {
  24.         retValue = NEGATIVE;
  25.         sem.notify();
  26.       }
  27.     }
  28.  
  29.     frame.add(new JLable(message));
  30.     frame.add(ok);
  31.     frame.add(cancel);
  32.  
  33.     frame.setVisible(true);
  34.  
  35.     while(retValue == UNSET) {
  36.       sem.wait();
  37.     }
  38.     return retValue;
  39.   }
  40. }