• java 图形化界面 布局管理器


     1 package Layout;
     2 import java.awt.*;
     3 import javax.swing.*;
     4 public class MyBorderLayout extends JFrame{
     5     private JButton b1 = new JButton("东");
     6     private JButton b2 = new JButton("南");
     7     private JButton b3 = new JButton("西");
     8     private JButton b4 = new JButton("北");
     9     private JButton b5 = new JButton("中");
    10 public MyBorderLayout(){
    11 
    12     setTitle("用户界面");
    13     setSize(500, 500);
    14     setLocation(100, 100);
    15     add(b1,BorderLayout.EAST);
    16     add(b2,BorderLayout.SOUTH);
    17     add(b3,BorderLayout.WEST);
    18     add(b4,BorderLayout.NORTH);
    19     add(b5,BorderLayout.CENTER);
    20  
    21     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    22     setVisible(true);
    23 }
    24     
    25     
    26     public static void main(String[] args) {
    27     MyBorderLayout l = new MyBorderLayout();
    28 
    29     }
    30 
    31 }
     1 package Layout;
     2 import java.awt.*;
     3 import java.util.HashMap;
     4 import java.util.Map;
     5 
     6 import javax.swing.*;
     7 public class MyFlowLayout extends JFrame{
     8     private  Map<String,JButton> map = new HashMap();
     9     private  JButton b = new JButton();
    10    public MyFlowLayout(){
    11        map.put("B1",new JButton("B1"));
    12        map.put("B2",new JButton("B2"));
    13        map.put("B3",new JButton("B3"));
    14        map.put("B4",new JButton("B4"));
    15        map.put("B5",new JButton("B5")); 
    16        this.setLayout(new FlowLayout());
    17     //   this.setLayout(new FlowLayout(FlowLayout.LEFT));
    18     //   this.setLayout(new FlowLayout(FlowLayout.RIGHT));
    19        this.add(map.get("B1"));
    20        this.add(map.get("B2"));
    21        this.add(map.get("B3"));
    22        this.add(map.get("B4"));
    23        this.add(map.get("B5"));
    24        this.setTitle("用户界面");
    25        this.setSize(500, 400);
    26        this.setLocation(400, 500);
    27        this.setVisible(true);
    28    }
    29     
    30     
    31     public static void main(String[] args) {
    32  
    33          MyFlowLayout l = new MyFlowLayout();
    34     }
    35 
    36 }
     1 package Layout;
     2 import java.awt.*;
     3 import java.util.HashMap;
     4 import java.util.Map;
     5 import javax.swing.*;
     6 public class MyGridLayout extends JFrame {
     7     private  Map<String,JButton> map = new HashMap();
     8     public MyGridLayout (){
     9         
    10                map.put("B1",new JButton("B1"));
    11                map.put("B2",new JButton("B2"));
    12                map.put("B3",new JButton("B3"));
    13                map.put("B4",new JButton("B4"));
    14                map.put("B5",new JButton("B5"));
    15                map.put("B6",new JButton("B6"));
    16                map.put("B7",new JButton("B7"));
    17                map.put("B8",new JButton("B8"));
    18                map.put("B9",new JButton("B9"));
    19                this.add(map.get("B1"));
    20                this.add(map.get("B2"));
    21                this.add(map.get("B3"));
    22                this.add(map.get("B4"));
    23                this.add(map.get("B5"));
    24                this.add(map.get("B6"));
    25                this.add(map.get("B7"));
    26                this.add(map.get("B8"));
    27                this.add(map.get("B9"));
    28                
    29                this.setTitle("用户界面");
    30                this.setSize(500, 600);
    31                this.setLocation(500, 500);
    32                this.setVisible(true);
    33               this.setLayout(new GridLayout(3,3,15,15)); 
    34         
    35     }
    36     public static void main(String[] args) {
    37     MyGridLayout l = new MyGridLayout();
    38 
    39     }
    40 
    41 }
  • 相关阅读:
    java核心技术学习笔记之一程序设计环境
    java核心技术学习笔记之一程序设计概述
    Eclips入门教程
    strict aliasing
    GCC 内联汇编
    文件系统实现
    ucore lab2
    Vim 最强调试插件:vimspector
    X86保护机制
    ucore lab1
  • 原文地址:https://www.cnblogs.com/the-wang/p/6752877.html
Copyright © 2020-2023  润新知