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

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

2013-11-23 19:55:26  來源: Java高級技術 

    ()程序代碼及注釋

    ① TestFrame類

    TestFrame是Java運行主程序用來顯示用戶界面

 
import javaxswing*;
import javaawt*;
import javaawtevent*;
public class TestFrame extends JFrame
{
 //GUI所需組件
 public JPanel testPanel = null;
 public JButton testButton = null;
 public JFrame testFrame = null;
 public TestFrame()
 {
  //設置GUI為windows風格
  try
  {
   UIManagersetLookAndFeel(
   comsunjavaswingplafwindowsWindowsLookAndFeel);
  }
  catch (Exception ex)
  {
   Systemoutprintln(Exception: + ex);
  }
  testFrame = this;
  // 初始化GUI
  Dimension dimensions = ToolkitgetDefaultToolkit()getScreenSize();
  setSize(dimensionswidth / dimensionsheight /);
  setLocation(dimensionswidth/dimensionswidth/
  dimensionsheight/dimensionsheight/);
  testPanel = new JPanel();
  testButton = new JButton(開始線程);
  testPaneladd(testButton);
  getContentPane()add(testPanel);
  //增加按鈕testButton事件監聽器
  testButtonaddActionListener(new javaawteventActionListener() {
  public void actionPerformed(ActionEvent e) {
  TestThread testThread = new TestThread();//新生成一個處理事務線程
  testThreadstart();//啟動事務線程
  (new ThreadDiag(testFrame testThread
   正在執行請等待))start();//啟動等待提示框線程
  }
 });
 //增加testFrame事件監聽器
 addWindowListener(new WindowAdapter()
 {
  public void windowClosing(WindowEvent e) {
  Systemexit();
 }
 });
}
 public static void main(String[] args)
 {
  //主程序
  TestFrame testFrame = new TestFrame();
  testFramesetTitle(線程等待測試);
  testFrameshow();
 }
}

[]  []  []  []  


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