how to close a java frame with threads
- by user261002
I have a java frame that I want to close it automatically after 3 or 4 seconds. I found out I must used threads. but I dont know how exactly to do it, this a dumy part of my code :
package intro;
import java.awt.*;
import java.io.IOException;
//import view.LangMenu;
public class IntroClass extends Frame {
private int _screenWidth = 0;
private int _screenHeight = 0;
private int _screenCenterx = 0;
private int _screenCentery = 0;
//private static final String SOUND_PATH="/sounds/introSound.midi";
public IntroClass() {
Toolkit thisScreen = Toolkit.getDefaultToolkit();
Dimension thisScrrensize = thisScreen.getScreenSize();
_screenWidth = thisScrrensize.width;
_screenHeight = thisScrrensize.height;
_screenCenterx = _screenWidth / 2;
_screenCentery = _screenHeight / 2;
setBackground(Color.pink);
Label lbl = new Label("Welcome To Dots Game. Samaneh Khaleghi", Label.CENTER);
add(lbl);
setUndecorated(true);
setLocation((_screenCenterx*50)/100,_screenCentery-(_screenCentery*50)/100);
setSize((_screenWidth * 50) / 100, (_screenHeight * 50) / 100);
WaitClass r = new WaitClass();
r.start();
view.DotsBoardFrame d=new view.DotsBoardFrame();
main.Main.showScreen(d);
}
class WaitClass extends Thread {
boolean running = true;
public void run() {
while (running) {
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
}