()程序代码及注释
① 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();
}
}
[] [] [] []