Posted on 2005-07-13 14:04
bigseal 閱讀(1357)
評論(0) 編輯 收藏
AWT是JFC(Java基本類)的核心,為JFC的構成提供了以下的基本結構:
- 代理事件模型
- 輕量構件
- 剪貼板和數據傳輸
- 打印和無鼠標操作
Java抽象窗口工具集有四個主要的類,即:構件類(Component)、容器類(Container)、圖形類(Graphics)、和布局管理類(LayoutManager和LayoutMangager2)。容器包含構件,布局管理器確定容器內構件的位置和形狀。圖形(Graphics)類提供在構件中顯示文本框和圖形的方法。
1.強制一個容器布置它的構件
在任何時間給定的構件都是有效(valid)或無效(invalid)的。無效的構件需要被布置,而有效的構件不需要。訪問一個 無效容器(它的同位體已經產生)的validate()引起對容器layout()方法的調用。使構件無效的過程不僅使構件自己變得無效,而且也會使構件所在的容器變的無效。
使構件無效的Component和Container方法:
void Component.addNotify()
void Component.show() (invalidates parent container)
void Component.hide() (invalidates parent container)
void Component.reshap(int x,int y,int width,int height)
void Component.setSize(int width,int height)
void Component.setBounds(int x,int y,int width,int height)
void Component.setLayout(LayoutManager)
void Container.add(Component)
void Container.remove(Component)
void Container.removeAll(Component)
void Container.setLayout(LayoutManager)
因此我們可以把希望重新布置的構件設置為無效,然后調用該構件父容器的validate()方法即可。