Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
karthikeya Boyini

Here, we are activating a frame. For deactivation, we have used dispose −

Thread.sleep(2000);
frame.setVisible(false);

The frame first activates and then deactivates after 2 seconds since we have set sleep to 2000 miliseconds.

The following is an example to activate and deactivate JFrame −

Example

import java.awt.Frame;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class SwingDemo {
   public static void main(String[] args) throws InterruptedException {
      JFrame frame = new JFrame();
      frame.add(new JLabel("Demo"));
      frame.pack();
      frame.setVisible(true);
      Thread.sleep(2000);
      frame.setState(Frame.ICONIFIED);
      Thread.sleep(2000);
      frame.setVisible(false);
      frame.dispose();
      System.exit(0);
   }
}

The output is as follows displaying the frame −

Output

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.