网格布局

package First;

import java.awt.*;
import javax.swing.*;

public class myframe {
    JPanel p=new JPanel(new  GridLayout(3,3,5,5));
        JFrame f;
        //JPanel p1;
        JButton b1;
        JButton b2;
        JLabel l1;
        JLabel l2;
        JTextField t1;
        JTextField t2;
        public myframe(){
            //Container c=getContentPane();
            //c.setLayout(new GridLayout(3,3));
            
            //c.add(p);
            f=new JFrame("网格布局管理器");
            //p1=new JPanel();
            b1=new JButton("确定");
            b2=new JButton("取消");
            t1=new JTextField(10);
            t2=new JTextField(10);
            l1=new JLabel("  用户名:");
            l2=new JLabel("  口令:");
            f.setSize(400,200);
            f.setVisible(true);
            f.add(p);
            p.add(l1);
            p.add(t1);
            p.add(l2);
            p.add(t2);
            p.add(b1);
            p.add(b2);
        }
        //private Container getContentPane() {
            // TODO Auto-generated method stub
            //return null;
        //}
        public static void main(String[] args){
            new myframe();
        }
    }

运行结果:

posted on 2019-05-17 14:47  万能G  阅读(99)  评论(0编辑  收藏  举报

导航