黑马程序员技术交流社区

标题: 图形化界面基础代码 [打印本页]

作者: ℃葫芦    时间: 2015-8-17 21:56
标题: 图形化界面基础代码
  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. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2