② 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();
}
}
[] [] [] []