Advertisement
paulolol

Untitled

Jan 3rd, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. @Override
  2.     public void action(ActionEvent e) {
  3.         attendre(3).start(); //3 est le temps en secondes, tu peux le changer
  4.         JOptionPane.showMessageDialog((Component) e.getSource(), alea);
  5.     }
  6.  
  7.     private Timer attendre(int seconds) {
  8.         ActionListener fermer = new ActionListener() {
  9.  
  10.             @Override
  11.             public void action(ActionEvent e) {
  12.                 Window[] fenetre = Window.getWindows();
  13.                 for (Window fenetre : windows) {
  14.                     if (fenetre instanceof JDialog) {
  15.                         JDialog dialog = (JDialog) window;
  16.                         if (dialog.getContentPane().getComponentCount() == 1
  17.                             && dialog.getContentPane().getComponent(0) instanceof JOptionPane){
  18.                             dialog.dispose();
  19.                         }
  20.                     }
  21.                 }
  22.  
  23.             }
  24.  
  25.         };
  26.         Timer t = new Timer(seconds * 1000, close);
  27.         t.setRepeats(false);
  28.         return t;
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement