Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void action(ActionEvent e) {
- attendre(3).start(); //3 est le temps en secondes, tu peux le changer
- JOptionPane.showMessageDialog((Component) e.getSource(), alea);
- }
- private Timer attendre(int seconds) {
- ActionListener fermer = new ActionListener() {
- @Override
- public void action(ActionEvent e) {
- Window[] fenetre = Window.getWindows();
- for (Window fenetre : windows) {
- if (fenetre instanceof JDialog) {
- JDialog dialog = (JDialog) window;
- if (dialog.getContentPane().getComponentCount() == 1
- && dialog.getContentPane().getComponent(0) instanceof JOptionPane){
- dialog.dispose();
- }
- }
- }
- }
- };
- Timer t = new Timer(seconds * 1000, close);
- t.setRepeats(false);
- return t;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement