zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然JAVA图形界面编程学习笔记:布局管理器

    import java.awt.FlowLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JButton ;
    import javax.swing.JLabel ;
    
    public class AbsoluteLayoutDemo01{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ; 
            frame.setLayout(null) ;
            JLabel title = new JLabel("www.mldnjava.cn") ;
            JButton enter = new JButton("进入") ;
            JButton help = new JButton("帮助") ;
            frame.setSize(280,123) ;
            title.setBounds(45,5,150,20) ;
            enter.setBounds(10,30,80,20) ;
            help.setBounds(100,30,80,20) ;
            frame.add(title) ;
            frame.add(enter) ;
            frame.add(help) ;
            frame.setVisible(true) ;
        }
    };
    import java.awt.BorderLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JButton ;
    
    public class BorderLayoutDemo01{
    	public static void main(String args[]){
    		JFrame frame = new JFrame("Welcome To MLDN") ; 
    		frame.setLayout(new BorderLayout(3,3)) ;
    		frame.add(new JButton("东(EAST)"),BorderLayout.EAST) ;
    		frame.add(new JButton("西(WEST)"),BorderLayout.WEST) ;
    		frame.add(new JButton("南(SOUTH)"),BorderLayout.SOUTH) ;
    		frame.add(new JButton("北(NORTH)"),BorderLayout.NORTH) ;
    		frame.add(new JButton("中(CENTER)"),BorderLayout.CENTER) ;
    		frame.setSize(280,123) ;
    		frame.setVisible(true) ;
    	}
    };
    

      

    import java.awt.CardLayout ;
    import java.awt.Container ;
    import javax.swing.JFrame ;
    import javax.swing.JLabel ;
    
    public class CardLayoutDemo01{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ; 
            CardLayout card = new CardLayout() ;
            frame.setLayout(card) ;
            Container con = frame.getContentPane() ;
            con.add(new JLabel("标签-A",JLabel.CENTER),"first") ;
            con.add(new JLabel("标签-B",JLabel.CENTER),"second") ;
            con.add(new JLabel("标签-C",JLabel.CENTER),"thrid") ;
            con.add(new JLabel("标签-D",JLabel.CENTER),"fourth") ;
            con.add(new JLabel("标签-E",JLabel.CENTER),"fifth") ;
            frame.pack() ;
            frame.setVisible(true) ;
            card.show(con,"thrid") ;
            for(int i=0;i<5;i++){
                try{
                    Thread.sleep(3000) ;
                }catch(InterruptedException e){}
                card.next(con) ;
            }
            
        }
    };
    import java.awt.FlowLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JButton ;
    
    public class FlowLayoutDemo01{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ; 
            frame.setLayout(new FlowLayout(FlowLayout.CENTER,3,3)) ;
            JButton but = null ;
            for(int i=0;i<9;i++){
                but = new JButton("按钮-"+ i) ;
                frame.add(but) ;
            }
            frame.setSize(280,123) ;
            frame.setVisible(true) ;
        }
    };
    import java.awt.GridLayout ;
    import javax.swing.JFrame ;
    import javax.swing.JButton ;
    
    public class GridLayoutDemo01{
        public static void main(String args[]){
            JFrame frame = new JFrame("Welcome To MLDN") ; 
            frame.setLayout(new GridLayout(3,5,3,3)) ;
            JButton but = null ;
            for(int i=0;i<13;i++){
                but = new JButton("按钮-"+ i) ;
                frame.add(but) ;
            }
            frame.pack() ;
            frame.setVisible(true) ;
        }
    };
  • 相关阅读:
    mysql pt-osc
    mysql表分区,mysql分区表
    mysql5.5无法启动,Can't open and lock privilege tables: Table 'mysql.host' doesn't exist 问题的解决方法
    mysql压缩表,mysql行压缩与页压缩
    mybase7破解
    (1.5)es集群部署运维【最佳实践】
    kafka基础概念
    midway日志体系
    midwayjs 使用egg-mysql
    midway mysql egg-mysql 配置 基础操作 增删改查
  • 原文地址:https://www.cnblogs.com/tszr/p/12398794.html
Copyright © 2011-2022 走看看