FlowLayout 救助

来源:互联网 发布:java box2d 编辑:程序博客网 时间:2024/05/01 06:04

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

 

 

public class TestFlowLayout extends JFrame {                              //这里为什么要用extends啊?

 

  public TestFlowLayout(String title) {
    super(title);
    init();
  }
                                                                                          //这一段代码也看不懂,括号里面为什么要写上String title啊?下面为什么要用上super(title); 以及init()???
  
  private void init() {
    this.setSize(300, 300);//设置窗体的尺寸
    this.setLocationRelativeTo(null);//让窗体在屏幕中居中
   
    JPanel panel = new JPanel();                                                 //不知道这段代码在这里的用意是什么。
    FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
    panel.setLayout(layout);
    panel.add(new JButton("btn1"));
    panel.add(new JButton("btn2"));
    panel.add(new JButton("btn3"));
    panel.add(new JButton("btn4"));
    panel.add(new JButton("btn5"));
    panel.add(new JButton("btn6"));
    panel.add(new JButton("btn7"));
   
    this.getContentPane().add(panel);
   
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
  }
 
  /**
   * @param args
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    new TestFlowLayout("my first frame");
  }

}
这是我们老师给我们写的一段代码,但是我看不太懂,请高手指点一点,谢谢。