熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java高級技術 >> 正文

用JAVA實現線程等待提示框[3]

2022-06-13   來源: Java高級技術 

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

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/Java/gj/201311/27677.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.