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();
        }
    }
    
    

    运行结果

  • 相关阅读:
    ps | grep排除grep这个进程
    树莓派3B安装LEDE
    从路由器镜像中提取uImage头信息
    提取路由器固件中的squashfs
    javascript监听按键
    linux 英汉词典程序shell+postgresql版
    树莓派(centos7)安装mysql
    在线视频下载利器——youtube-dl
    使用curl自动签到百度贴吧
    极路由hc5661安装tcpdump
  • 原文地址:https://www.cnblogs.com/d534/p/15111563.html
Copyright © 2011-2022 走看看