zoukankan      html  css  js  c++  java
  • 临时

     1 class Demo07GridBagLayout {
     2     void makeButton(String s, JFrame frame, GridBagLayout gbLayout, GridBagConstraints gbConstraints) {
     3         JButton button = new JButton(s);
     4         gbLayout.setConstraints(button, gbConstraints);
     5         frame.add(button);
     6     }
     7     public void run() {
     8         JFrame frame = new JFrame("第七个GUI程序 -> 拨号盘");
     9         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    10         frame.setBounds(200, 300, 300, 160);
    11         GridBagLayout gbLayout = new GridBagLayout();                   // 创建GirdBagLayout布局管理器
    12         GridBagConstraints gbConstraints = new GridBagConstraints();
    13         frame.setLayout(gbLayout);                                      // 使用GirdBagLayout布局管理器
    14         gbConstraints.fill = GridBagConstraints.BOTH;                   // 组件填充显示区域
    15         gbConstraints.weightx = 0.0;                                    // 恢复默认值
    16         gbConstraints.gridwidth = GridBagConstraints.REMAINDER;          // 结束行
    17         JTextField textField = new JTextField("13612345678");
    18         gbLayout.setConstraints(textField, gbConstraints);
    19         frame.add(textField);
    20         gbConstraints.weightx = 0.5;                                    // 指定分配区域
    21         gbConstraints.weighty = 0.2;
    22         gbConstraints.gridwidth = 1;
    23         makeButton("7", frame, gbLayout, gbConstraints);                // 调用方法,添加按钮
    24         makeButton("8", frame, gbLayout, gbConstraints);
    25         gbConstraints.gridwidth = GridBagConstraints.REMAINDER;         // 结束行
    26         makeButton("9", frame, gbLayout, gbConstraints);
    27         gbConstraints.gridwidth = 1;                                    // 重置gridwidth
    28         makeButton("4", frame, gbLayout, gbConstraints);
    29         makeButton("5", frame, gbLayout, gbConstraints);
    30         gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    31         makeButton("6", frame, gbLayout, gbConstraints);
    32         gbConstraints.gridwidth = 1;
    33         makeButton("1", frame, gbLayout, gbConstraints);
    34         makeButton("2", frame, gbLayout, gbConstraints);
    35         gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    36         makeButton("3", frame, gbLayout, gbConstraints);
    37         gbConstraints.gridwidth = 1;
    38         makeButton("返回", frame, gbLayout, gbConstraints);
    39         gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    40         makeButton("拨号", frame, gbLayout, gbConstraints);
    41         // gbConstraints.gridwidth = 1;
    42         frame.setVisible(true);                                         // 设置窗格可见
    43     }
    44 }
    45 
    46 class E {
    47     public static void main(String args[]) {
    48         new Demo07GridBagLayout().run(); // 为什么第一列会比较宽
    49     }
    50 }

  • 相关阅读:
    HDU 1394Minimum Inversion Number 数状数组 逆序对数量和
    2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟
    Codeforces 723C. Polycarp at the Radio 模拟
    hihoCode 1078 : 线段树的区间修改
    hihocode 1077 : RMQ问题再临-线段树
    POJ 2352Stars 树状数组
    Codeforces 714C. Sonya and Queries Tire树
    Codeforces 710C. Magic Odd Square n阶幻方
    Codeforces 709C 模拟
    ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT
  • 原文地址:https://www.cnblogs.com/bpf-1024/p/12895094.html
Copyright © 2011-2022 走看看