ThreadDiag.java
上传用户:tie2000000
上传日期:2022-07-03
资源大小:4k
文件大小:2k
- package sendmsg;
- import java.awt.*;
- import javax.swing.*;
- public class ThreadDiag implements Runnable
- {
- boolean stop=false;
- private Thread t=null;
- private dosend ds = null;//实际调用时就是TestThread事务处理线程 网管网bitsCN_com
- private String messages = "";//提示框的提示信息
- private JFrame parentFrame = null;//提示框的父窗体
- private JDialog clueDiag = null;// “线程正在运行”提示框
- private JTextArea ta=null;
- private Dimension dimensions = Toolkit.getDefaultToolkit().getScreenSize();
- private int width = dimensions.width / 4, height = 60;
- private int left = 0, top = 0;
- public ThreadDiag(JFrame parentFrame, dosend ds, String messages,Thread t,JTextArea z)
- {
- this.parentFrame = parentFrame;
- this.ds = ds;
- this.messages = messages;
- this.t=t;
- ta=z;
- initDiag();//初始化提示框
- }
- protected synchronized void initDiag()
- {
- clueDiag = new JDialog(parentFrame,t+"正在执行,请等待...",false);
- clueDiag.setCursor(new Cursor(Cursor.WAIT_CURSOR));
- JPanel testPanel = new JPanel();
- JTextArea testArea = new JTextArea(messages);
- testArea.setEditable(false);
- clueDiag.getContentPane().add(testPanel);
- testPanel.add(testArea);
- clueDiag.addWindowListener(new java.awt.event.WindowAdapter() {
- public synchronized void windowClosing(java.awt.event.WindowEvent e) {
- t.stop(); //**********************此处若调用ds.quit()在等待过程中若开始新线程将无法正常终止
- //ta.setText("正在终止"+t+"请稍后");
- clueDiag.dispose();
- }
- });
- (new closediag(ds,ta,clueDiag,t)).start();//启动关闭提示框线程
- }
- public synchronized void run(){
- //显示提示框
- int left = (dimensions.width - width)/2;
- int top = (dimensions.height - height)/2;
- clueDiag.setSize(new Dimension(width,height));
- clueDiag.setLocation(left, top);
- clueDiag.show();
- }
- }