70 lines
1.7 KiB
Java
70 lines
1.7 KiB
Java
package com.tarisan.chipcard.gui;
|
|
|
|
|
|
import javax.swing.JDialog;
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
|
|
/**
|
|
* @author jjrider
|
|
*/
|
|
public class AutomaticCloseDialog extends JDialog implements ActionListener,Runnable {
|
|
|
|
private int intNumeroSegundos=5;
|
|
private Thread objThread=null;
|
|
|
|
public AutomaticCloseDialog(String strTitle,String strMensaje,int intNumeroSegundos){
|
|
super();
|
|
setUndecorated(false);
|
|
setSize(320,150);
|
|
this.intNumeroSegundos=intNumeroSegundos;
|
|
setTitle(strTitle);
|
|
getContentPane().setLayout(null);
|
|
|
|
JLabel label=new JLabel(strMensaje);
|
|
label.setBounds(40,40,300,20);
|
|
getContentPane().add(label);
|
|
|
|
JButton btnAceptar=new JButton("Aceptar");
|
|
btnAceptar.setActionCommand("Aceptar");
|
|
btnAceptar.addActionListener(this);
|
|
btnAceptar.setBounds(115,80,90,20);
|
|
getContentPane().add(btnAceptar);
|
|
objThread=new Thread(this);
|
|
validate();
|
|
centerOnScreen(this);
|
|
objThread.start();
|
|
show();
|
|
|
|
}
|
|
|
|
public void actionPerformed(ActionEvent e){
|
|
hide();
|
|
}
|
|
|
|
public static void centerOnScreen(JDialog dialog){
|
|
if(dialog==null)
|
|
return;
|
|
Dimension dimFrame=java.awt.Toolkit.getDefaultToolkit().getScreenSize();
|
|
Dimension dimDialog=dialog.getSize();
|
|
int distanceWidth=dimFrame.width-dimDialog.width;
|
|
distanceWidth=distanceWidth/2;
|
|
int distanceHeight=dimFrame.height-dimDialog.height;
|
|
distanceHeight=distanceHeight/2;
|
|
dialog.setBounds(distanceWidth,distanceHeight,dimDialog.width,dimDialog.height);
|
|
}
|
|
|
|
public void run(){
|
|
try{
|
|
objThread.sleep(intNumeroSegundos*1000);
|
|
}catch(Exception err){
|
|
}
|
|
hide();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|