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

    运行结果

  • 相关阅读:
    App案例分析——XBMC
    四则运算题目生成程序(基于控制台)
    第一次结对编程
    第二次作业--摩拜单车
    第0次作业
    团队编程作业1-团队展示与选题
    结对编程1-模块化
    APP案例分析
    第1次作业
    第0道作业
  • 原文地址:https://www.cnblogs.com/d534/p/15111563.html
Copyright © 2011-2022 走看看