Java线程等待 用JAVA实现线程等待提示框[2]
用JAVA实现线程等待提示框[2]
![Java线程等待 用JAVA实现线程等待提示框[2]](http://img.zhputi.com/uploads/66c6/66c69b310d595e4006fe01c0cecd9bbd12841.jpg)
( )程序代码及注释
① 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( 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 / dimensions height / ); setLocation(dimensions width/ dimensions width/ dimensions height/ dimensions height/ ); 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( ); } });} public static void main(String[] args) { //主程序 TestFrame testFrame = new TestFrame(); testFrame setTitle( 线程等待测试 ); testFrame show(); }}
lishixinzhi/Article/program/Java/gj/201311/27676