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);
    	}
    }
    
  • 相关阅读:
    Linux系统IP地址
    系统网络概述
    系统内存和CPU管理、监控
    系统磁盘资源
    Linux与DOS的常用命令比较
    傻瓜式破解linux--rootpassword
    【iOS】彩虹渐变色 的 Swift 实现
    Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题
    OpenCV Haar AdaBoost源代码改进(比EMCV快6倍)
    【Hibernate步步为营】--双向关联一对一映射具体解释(一)
  • 原文地址:https://www.cnblogs.com/sincoolvip/p/8360126.html
Copyright © 2011-2022 走看看