您现在的位置: 天极网 > 开发频道 > 用JAVA实现线程等待提示框
全文

用JAVA实现线程等待提示框

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

  (3)程序代码及注释

  ① TestFrame类

  TestFrame是Java运行主程序,用来显示用户界面。

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class TestFrame extends JFrame

{

 //GUI所需组件

 public JPanel testPanel = null;

 public JButton testButton = null;

 public JFrame testFrame = null;

 public TestFrame()

 {

  //设置GUI为windows风格

  try

  {

   UIManager.setLookAndFeel(

   "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

  }

  catch (Exception ex)

  {

   System.out.println(“Exception: ” + ex);

  }

  testFrame = this;

  // 初始化GUI

  Dimension dimensions = Toolkit.getDefaultToolkit().getScreenSize();

  setSize(dimensions.width /2, dimensions.height /2);
  
  setLocation(dimensions.width/2-dimensions.width/4,
  
  dimensions.height/2-dimensions.height/4);

  testPanel = new JPanel();

  testButton = new JButton("开始线程");

  testPanel.add(testButton);

  getContentPane().add(testPanel);

  //增加按钮testButton事件监听器

  testButton.addActionListener(new java.awt.event.ActionListener() {

  public void actionPerformed(ActionEvent e) {

  TestThread testThread = new TestThread();//新生成一个处理事务线程

  testThread.start();//启动事务线程

  (new ThreadDiag(testFrame, testThread ,

   "正在执行,请等待......")).start();//启动等待提示框线程

  }

 });

 //增加testFrame事件监听器

 addWindowListener(new WindowAdapter()

 {

  public void windowClosing(WindowEvent e) {

  System.exit(0);
  
 }

 });

}

 public static void main(String[] args)

 {

  //主程序

  TestFrame testFrame2 = new TestFrame();

  testFrame2.setTitle("线程等待测试");

  testFrame2.show();

 }

}
共4页。 9 1 2 3 4 :

软件资讯·软件下载尽在天极软件

相关搜索:
相关文章及软件
关注此文读者还看过
热门关注
特别推荐
网友关注
软件下载
娱乐下载
驱动下载
文章排行
本周
本月
最近更新
关于我们|About us|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2009 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 渝ICP证B2-20030003号
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众