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

更多

数码相机
MP4
LCD
机箱
音箱

天极网 > 开发频道>用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订阅|友情合作|加入我们|天极动态|网站地图|意见反馈|MSN/QQ上看天极
Copyright (C) 1999-2012 Yesky.com, All Rights Reserved 版权所有 天极网络