GUI
作者:互联网
核心技术 Swing 、AWT
component 组件
button 按钮
container 容器
Frame frame = new Frame();一个最基础的界面,可以设置各种属性
Panel可以看做一个空间,但是不能单独存在,必须靠frame
Panel panel = new Panel();
frame.add(panel);空间放到界面里
点击关闭按钮,关闭界面
frame.addWindowListener(new WindowAdapter() {
//窗口点击关闭 时做的事情
@Override
public void windowClosing(WindowEvent e) {
//结束程序
System.exit(0);
}
});
Button button = new Button();组件-按钮
//设置为流式布局
frame.setLayout(new FlowLayout());
//东西南北中布局
Button east = new Button("East");
Button west = new Button("West");
Button south = new Button("South");
Button north = new Button("North");
Button center = new Button("Center");
frame.add(east, BorderLayout.EAST);
frame.add(west,BorderLayout.WEST);
frame.add(south,BorderLayout.SOUTH);
frame.add(north,BorderLayout.NORTH);
frame.add(center,BorderLayout.CENTER);
//表格布局 Grid
Button btn1 = new Button("btn1");
Button btn2 = new Button("btn2");
Button btn3 = new Button("btn3");
Button btn4 = new Button("btn4");
Button btn5 = new Button("btn5");
Button btn6 = new Button("btn6");
//表格布局设置3行2列
frame.setLayout(new GridLayout(3,2));
frame.add(btn1);
frame.add(btn2);
frame.add(btn3);
frame.add(btn4);
frame.add(btn5);
frame.add(btn6);
标签:BorderLayout,GUI,btn1,add,frame,new,Button 来源: https://www.cnblogs.com/fy2014/p/16311503.html