![](https://csdnimg.cn/release/download_crawler_static/28123567/bg8.jpg)
public static void main( String args[] ) {
ThreadDemo thread1=new ThreadDemo( “T1”);
ThreadDemo thread2=new ThreadDemo( “T2”);
ThreadDemo thread3=new ThreadDemo( “T3”);
thread1.start();
thread2.start();
thread3.start();
}
}
10. 编写程序,在屏幕上显示带标题的窗口,并添加一个按钮。当用户单击按钮时,结束程
序。
// Programme Name ButtonEventDemo.java
import javax.swing.*;
import java.awt.event.*;
public class ButtonEventDemo extends JPanel implements ActionListener{
protected JButton b1; //声明一个按钮对象
public ButtonEventDemo() { //构造方法
ImageIcon ButtonIcon = new ImageIcon("images/green.png"); //创建按钮的图标对
象
b1 = new JButton(" 退出按钮 ", ButtonIcon); //生成按钮对象
b1.setMnemonic(KeyEvent.VK_E); //设置 b1 的助记符是 Alt+E
b1.setToolTipText(" 这是退出按钮。 "); // 设置按钮提示条
this.add(b1); //往面板对象中加载按钮
b1.addActionListener(this); //本类对象注册为按钮的事件监听器
}
public void actionPerformed(ActionEvent e){ //按钮事件响应方法
System.exit(0); //按 b1 则退出主程序
}
private static void createGUI() { // 创建窗体
JFrame.setDefaultLookAndFeelDecorated(true); // 设置 java 隐含观感
JFrame frame = new JFrame("按钮测试 "); // 生成应用程序主窗体
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置关闭时隐含操作