JPanel画板

2021年09月16日 阅读数:3
这篇文章主要向大家介绍JPanel画板,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。
public class JPanelTest extends JFrame{

    public JPanelTest() {
        // TODO Auto-generated constructor stub
    Container c = getContentPane();
    setLayout(new GridLayout(2,2,10,10));
    JPanel p1 = new JPanel(new GridLayout(1, 3,10,10));
    JPanel p2 = new JPanel(new GridLayout(1, 2,10,10));
    JPanel p3 = new JPanel(new GridLayout(1, 2,10,10));
    JPanel p4 = new JPanel(new GridLayout(2, 1,10,10));
    p1.add(new JButton("1"));
    p1.add(new JButton("2"));
    p1.add(new JButton("3"));
    p2.add(new JButton("4"));
    p2.add(new JButton("5"));
    p3.add(new JButton("6"));
    p3.add(new JButton("7"));
    p4.add(new JButton("8"));
    p4.add(new JButton("9"));
    c.add(p1);
    c.add(p2);
    c.add(p3);
    c.add(p4);
    setSize(1000,1000);
    setVisible(true);
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new JPanelTest();
    }

}