首页产品库评测行情新闻|手机数码笔记本台式机DIY硬件数字家庭数码相机办公外设|软件下载游戏开发|社区

更多

数码相机
MP4
LCD
机箱
音箱

天极网 > 开发频道>用JAVA实现线程等待提示框

用JAVA实现线程等待提示框

2001-12-30 11:17作者:吴黎兵出处:yesky责任编辑:方舟


  ② TestThread类

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

public class TestThread extends Thread

 {

  public void run()

  {

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

   {

    System.out.println(i);

   }
  
  }

 }

  ③ ThreadDiag类

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

import java.awt.*;

import javax.swing.*;

public class ThreadDiag extends Thread

{

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

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

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

 private JDialog clueDiag = 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, Thread currentThread, String messages)

 {

  this.parentFrame = parentFrame;

  this.currentThread = currentThread;

  this.messages = messages;

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

 }

 protected void initDiag()
 
 {

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

  clueDiag.setCursor(new Cursor(Cursor.WAIT_CURSOR));

  JPanel testPanel = new JPanel();

  JLabel testLabel = new JLabel(messages);

  clueDiag.getContentPane().add(testPanel);

  testPanel.add(testLabel);

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

 }

public 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();

 }

}
共4页。 9 1 2 3 4 :

关注此文的读者还看过:

返回开发频道首页

软件频道最新更新

热点推荐

天极服务|关于我们|About us|网站律师|RSS订阅|友情合作|加入我们|天极动态|网站地图|意见反馈|MSN/QQ上看天极
Copyright (C) 1999-2012 Yesky.com, All Rights Reserved 版权所有 天极网络