Sunday, 29 March 2015

Java code for Auto close the popup with time gap

package Flowell_testing;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.swing.*;
import org.junit.Test;


public class App4 {
    @Test
    public void Login1() throws Exception {
    System.out.println("*******Love u mom*******");
   
    JFrame f = new JFrame();
    final JDialog dialog = new JDialog(f, "Test", true);
    JLabel label = new JLabel("Please wait.." );
    dialog.setSize(600, 600);
    //Must schedule the close before the dialog becomes visible
    ScheduledExecutorService s = Executors.newSingleThreadScheduledExecutor();     
    dialog.add(label);
    dialog.setLocationRelativeTo(f);
    dialog.pack();   //Dynamic size increase
    s.schedule(new Runnable() {
       public void run() {
           dialog.setVisible(false); //should be invoked on the EDT
           dialog.dispose();
       }
    }, 1000, TimeUnit.MILLISECONDS);

    dialog.setVisible(true); // if modal, application will pause here

    System.out.println("Dialog closed");
     
     
    }
    
}