//BorderLayoutDemo边界布局管理器练习 import java.awt.*; import java.awt.event.*; @SuppressWarnings("serial") public class BorderLayoutDemo extends Frame { private final String names[] = { "hide north", "hide south", "hide east", "hide west", "hide center" }; private final String locations[] = { BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, BorderLayout.WEST, BorderLayout.CENTER }; private Button[] buttons = new Button[5]; public BorderLayoutDemo(String title) { super(title); final BorderLayout layout = (BorderLayout) this.getLayout(); ActionListener listener = new ActionListener() { // 事件监听器 public void actionPerformed(ActionEvent event) { for (int i = 0; i < buttons.length; i++) if (event.getSource() == buttons[i]) buttons[i].setVisible(false); else buttons[i].setVisible(true); layout.layoutContainer(BorderLayoutDemo.this); } }; for (int i = 0; i < buttons.length; i++) { buttons[i] = new Button(names[i]); buttons[i].addActionListener(listener); add(buttons[i], locations[i]); } setSize(250, 250); setVisible(true); } public static void main(String args[]) { new BorderLayoutDemo("hello"); } }
posted on 2010-02-18 22:08 台哥编程课堂 阅读(349) 评论(0) 编辑 收藏 举报