首页 > 其他分享 >GUI-6-练习代码组合框及按钮-2022-12-7

GUI-6-练习代码组合框及按钮-2022-12-7

时间:2022-12-07 15:55:13浏览次数:61  
标签:12 BorderLayout GUI Button add 2022 new frame Panel

package com.lr.guifirstdemo;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class testDemo05 {
public static void main(String[] args) {
Frame frame = new Frame();
frame.setLayout(new GridLayout(2,1));

frame.setBounds(200,200,500,400);
frame.setBackground(Color.black);
frame.setVisible(true);

Panel p1 = new Panel(new BorderLayout());
Panel p2 = new Panel(new GridLayout(2,1));
Panel p3 = new Panel(new BorderLayout());
Panel p4 = new Panel(new GridLayout(2,2));

p1.add(new Button("east-1"),BorderLayout.EAST);
p1.add(new Button("west-1"),BorderLayout.WEST);
p2.add(new Button("p2-btn-1"));
p2.add(new Button("p2-btn-2"));
p1.add(p2,BorderLayout.CENTER);

p3.add(new Button("east-2"),BorderLayout.EAST);
p3.add(new Button("west-2"),BorderLayout.WEST);
for (int i = 0; i < 4; i++) {
p4.add(new Button("for-"+i));
}
p3.add(p4,BorderLayout.CENTER);

frame.add(p1);
frame.add(p3);

frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

}
}

标签:12,BorderLayout,GUI,Button,add,2022,new,frame,Panel
From: https://www.cnblogs.com/RUI2022/p/16963321.html

相关文章