修飾子
public class Container
父類別
java.awt.Component
實作介面
ImageObserver
MenuContainer
Serializable
建構子
Container()
常用方法
名稱 敘述 add() 加入元件 remove() 移除元件 removeAll() 移除所有元件 setLayout() 設定元件的版面配置
舉例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import java.awt.*; import java.awt.event.*; public class AWTDemo { public static void main(String[] args) { Frame frame = new Frame( "AWTDemo" ); frame.addWindowListener( new AdapterDemo()); Button button1 = new Button( "b1" ); Button button2 = new Button( "b2" ); Button button3 = new Button( "b3" ); Button button4 = new Button( "b4" ); Button button5 = new Button( "b5" ); frame.setLayout( new FlowLayout()); frame.add(button1); frame.add(button2); frame.add(button3); frame.add(button4); frame.add(button5); frame.pack(); frame.setVisible( true ); } } class AdapterDemo extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit( 0 ); } } /* 《程式語言教學誌》的範例程式 檔名:AWTDemo.java 功能:示範 Java 程式 作者:張凱慶 時間:西元 2012 年 3 月 */ |
此例建立 frame 之後,依次建立五個按鈕
9 10 11 12 13 | Button button1 = new Button( "b1" ); Button button2 = new Button( "b2" ); Button button3 = new Button( "b3" ); Button button4 = new Button( "b4" ); Button button5 = new Button( "b5" ); |
然後呼叫 Container 的 add() ,將五個按鈕加入 frame 裡
16 17 18 19 20 | frame.add(button1); frame.add(button2); frame.add(button3); frame.add(button4); frame.add(button5); |
編譯後執行,結果如下

中英文術語對照 | |
---|---|
類別 | class |
建構子 | constructor |
方法 | method |
您可以繼續參考
AWT 元件
相關目錄
Java API 分類導覽
Java 教材
首頁
參考資料
http://docs.oracle.com/javase/6/docs/api/java/awt/Container.html
沒有留言:
張貼留言