A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© ℃葫芦 中级黑马   /  2015-8-17 21:56  /  216 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. public class FrameDemo {

  2.         /**
  3.          * @param args
  4.          */
  5.         public static void main(String[] args) {

  6.                 Frame f = new Frame("my frame");
  7. //                f.setSize(500, 400);               
  8. //                f.setLocation(400, 200);
  9.                 f.setBounds(400, 200, 500, 400);               
  10.                 f.setLayout(new FlowLayout());//设置流式布局
  11.                
  12.                 Button but  = new Button("一个按钮");
  13.                
  14.                 f.add(but);//将按钮添加到窗体中。
  15.                
  16.                
  17.                 f.addWindowListener(new WindowAdapter() {

  18.                         @Override
  19.                         public void windowClosing(WindowEvent e) {
  20.                                
  21. //                                System.out.println("closing......."+e);
  22.                                 System.exit(0);
  23.                         }
  24.                        
  25.                 });
  26.                
  27.                
  28.                 //在按钮上加上一个监听。
  29.                 but.addActionListener(new ActionListener() {
  30.                        
  31.                         @Override
  32.                         public void actionPerformed(ActionEvent e) {
  33. //                                System.out.println("button run .....");
  34.                                 System.exit(0);
  35.                         }
  36.                 });
  37.                
  38.                 f.setVisible(true);
  39.                 System.out.println("over");
  40.         }

  41. }
复制代码

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马