- import javax.swing.JFrame;
- import javax.swing.JButton;
- import java.awt.GridLayout;
- public class Ch114 {
-
- JFrame fm;
- JButton btn1,btn2,btn3,btn4,btn5,btn6;
- Ch114()
- {
- JButton btn1=new JButton("xxx");
- JButton btn2=new JButton("xxxxxxx");
- JButton btn3=new JButton("xxxxxxxxxxx");
- JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
- JButton btn5=new JButton("xxx");
- JButton btn6=new JButton("x");
-
- fm=new JFrame("GridLayout");
- fm.setBounds(100, 100, 300, 200);
- fm.setVisible(true);
- fm.setResizable(true);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.setLayout(new GridLayout(3,2,5,5));
- fm.add(btn1);
- fm.add(btn2);
- fm.add(btn3);
- fm.add(btn4);
- fm.add(btn5);
- fm.add(btn6);
- }
-
- public static void main(String[] args) {
- new Ch114();
- }
- }
複製代碼 |