zoukankan      html  css  js  c++  java
  • 三种布局方式

    package windows;
    
    import java.awt.FlowLayout;
    
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    
    public class ShowFlowLayout extends JFrame{
    	public ShowFlowLayout(){
    		super.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 20));
    		add(new JLabel("姓名:"));
    		add(new JTextField(8));
    		add(new JLabel("邮箱:"));
    		add(new JTextField(8));
    		add(new JLabel("电话:"));
    		add(new JTextField(8));
    		
    	}
    	public static void main(String[] args) {
    		ShowFlowLayout frame =new ShowFlowLayout();
    		frame.setTitle("FlowLayout");
    		frame.setSize(500,200);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
    	}
    }
    
    package windows;
    
    import java.awt.GridLayout;
    
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    
    public class ShowGrigLayout extends JFrame{
    	public ShowGrigLayout() {
    		setLayout(new GridLayout(3, 2,5,5));
    		add(new JLabel("姓名:"));
    		add(new JTextField(8));
    		add(new JLabel("邮箱"));
    		add(new JTextField(8));
    		add(new JLabel("电话:"));
    		add(new JTextField(8));
    	}
    	public static void main(String[] args) {
    		ShowGrigLayout frame=new ShowGrigLayout();
    		frame.setTitle("GridLayout");
    		frame.setSize(200,125);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
    		
    	}
    }
    
    package windows;
    
    import java.awt.BorderLayout;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class ShowBorderLayout extends JFrame{
    	public ShowBorderLayout() {
    		setLayout(new BorderLayout(5, 10));
    		
    		add(new JButton("东"),BorderLayout.WEST);
    		add(new JButton("西"),BorderLayout.EAST);
    		add(new JButton("南"),BorderLayout.SOUTH);
    		add(new JButton("北"),BorderLayout.NORTH);
    		add(new JButton("中"),BorderLayout.CENTER);
    	}
    	public static void main(String[] args) {
    		ShowBorderLayout frame =new ShowBorderLayout();
    		frame.setTitle("BorderLayout");
    		frame.setSize(300, 200);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setVisible(true);
    	}
    }
    
  • 相关阅读:
    记一次git fatal: Unable to find remote helper for 'https'问题的解决
    LambdaMART简介——基于Ranklib源码(二 Regression Tree训练)
    LambdaMART简介——基于Ranklib源码(一 lambda计算)
    用中文把玩Google开源的Deep-Learning项目word2vec
    Ubuntu18.04 一次性升级Python所有库
    CSAPP家庭作业(第二章)
    两个有序链表序列的合并
    sublime text 3 配置Python开发环境
    Java课程设计-泡泡堂(个人)
    二叉树的先序建立与遍历
  • 原文地址:https://www.cnblogs.com/sincoolvip/p/8360126.html
Copyright © 2011-2022 走看看