zoukankan      html  css  js  c++  java
  • GUI 之 JPanel(面板)

    编写代码 JPanelDemo测试类

    package com.xiang.lesson05;
    
    import javax.swing.*;
    import java.awt.*;
    
    // JPanel面板
    public class JPanelDemo extends JFrame {
        public JPanelDemo() {
            Container container = getContentPane();
    //        表格布局
            container.setLayout(new GridLayout(2, 1, 10, 10));
    
            JPanel p1 = new JPanel(new GridLayout(1, 3));
            JPanel p2 = new JPanel(new GridLayout(2, 1));
            JPanel p3 = new JPanel(new GridLayout(5, 5));
            JPanel p4 = new JPanel(new GridLayout(3, 1));
    
    //        p1.add(new JButton("1"));
    //        p1.add(new JButton("2"));
    //        p1.add(new JButton("3"));
    
            for (int i = 0; i < 3; i++) {
                p1.add(new JButton("3"));
            }
    
            p2.add(new JButton("2"));
            p2.add(new JButton("2"));
    
    //        p3.add(new JButton("3"));
    //        p3.add(new JButton("3"));
    //        p3.add(new JButton("3"));
    //        p3.add(new JButton("3"));
    //        p3.add(new JButton("3"));
    //        p3.add(new JButton("3"));
    
    
            for (int i = 0; i < 25; i++) {
                p3.add(new JButton("3"));
            }
    
    //        p4.add(new JButton("4"));
    //        p4.add(new JButton("4"));
    //        p4.add(new JButton("4"));
    
            for (int i = 0; i < 3; i++) {
                p4.add(new JButton("4"));
            }
    
            container.add(p1);
            container.add(p2);
            container.add(p3);
            container.add(p4);
    
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setVisible(true);
            setBounds(100, 100, 500, 500);
            setBackground(Color.pink);
    
        }
    
        public static void main(String[] args) {
            new JPanelDemo();
        }
    }
    
    

    运行结果

  • 相关阅读:
    2013年 积木大赛
    Matlab 画图2
    Matlab 画图1
    Matlab 数值计算
    Matlab 条件循环函数
    Non Super Boring Substring 题解(hash+思维)
    Matlab 数组
    Matlab 矩阵
    L
    hdu 1671Phone List
  • 原文地址:https://www.cnblogs.com/d534/p/15111563.html
Copyright © 2011-2022 走看看