java

位置:IT落伍者 >> java >> 浏览文章

用JAVA实现线程等待提示框[3]


发布日期:2018年02月17日
 
用JAVA实现线程等待提示框[3]

② TestThread类

TestThread类是处理事务线程即在标准输出设备上显示从

public class TestThread extends Thread

{

public void run()

{

for (int i = ; i < ; i++ )

{

Systemoutprintln(i);

}

}

}

③ ThreadDiag类

ThreadDiag类用来显示线程正在运行提示框

import javaawt*;

import javaxswing*;

public class ThreadDiag extends Thread

{

private Thread currentThread = null;//实际调用时就是TestThread事务处理线程

private String messages = ;//提示框的提示信息

private JFrame parentFrame = null;//提示框的父窗体

private JDialog clueDiag = null;// 线程正在运行提示框

private Dimension dimensions = ToolkitgetDefaultToolkit()getScreenSize();

private int width = dimensionswidth / height = ;

private int left = top = ;

public ThreadDiag(JFrame parentFrame Thread currentThread String messages)

{

thisparentFrame = parentFrame;

thiscurrentThread = currentThread;

thismessages = messages;

initDiag();//初始化提示框

}

protected void initDiag()

{

clueDiag = new JDialog(parentFrame正在执行请等待true);

clueDiagsetCursor(new Cursor(CursorWAIT_CURSOR));

JPanel testPanel = new JPanel();

JLabel testLabel = new JLabel(messages);

clueDiaggetContentPane()add(testPanel);

testPaneladd(testLabel);

(new DisposeDiag())start();//启动关闭提示框线程

}

public void run()

{

//显示提示框

int left = (dimensionswidth width)/;

int top = (dimensionsheight height)/;

clueDiagsetSize(new Dimension(widthheight));

clueDiagsetLocation(left top);

clueDiagshow();

}

}

[] [] [] []

               

上一篇:用JAVA实现线程等待提示框[4]

下一篇:用JAVA实现线程等待提示框[2]