package bitter01; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class TestBitter { public static void main(String[] args) { Frame frame = new Frame(); frame.setVisible(true); frame.setSize(400,300); frame.setLocation(300,400); frame.setBackground(new Color(231, 109, 169)); frame.setLayout(new GridLayout(2,1)); Panel panel1 = new Panel(new BorderLayout()); Panel panel2 = new Panel(new GridLayout(2,1)); Panel panel3 = new Panel(new BorderLayout()); Panel panel4 = new Panel(new GridLayout(2,2)); panel1.add(new Button("East-1"),BorderLayout.EAST); panel1.add(new Button("West-1"),BorderLayout.WEST); panel2.add(new Button("panel2-btn-1")); panel2.add(new Button("panel2-btn-2")); panel1.add(panel2,BorderLayout.CENTER); panel3.add(new Button("East-2"),BorderLayout.EAST); panel3.add(new Button("West-2"),BorderLayout.WEST); for (int i = 1; i <=4; i++) { panel4.add(new Button("for-btn-"+i)); } /*panel4.add(new Button("p4-btn-1")); panel4.add(new Button("p4-btn-2")); panel4.add(new Button("p4-btn-3")); panel4.add(new Button("p4-btn-4"));*/ panel3.add(panel4,BorderLayout.CENTER); frame.add(panel1); frame.add(panel3); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); } }
总结:
-
Frame是一个顶级窗口,
-
Panel无法单独显示,必须添加到某个容器中。
-
布局管理器
-
流式布局
-
东西南北中
-
表格
-
-
大小、定位、背景颜色、可见性,监听。
4事件监听
事件监听:当某个事情