修飾子與參數
public void removeAll()
removeAll() 沒有回傳值 (return value) ,也不需要參數 (paramenter) 。
舉例如下
import java.awt.*;
import java.awt.event.*;
public class removeAllDemo implements ActionListener {
Frame frame;
Button button1, button2, button3, button4, button5;
public static void main(String[] args) {
new removeAllDemo();
}
public removeAllDemo() {
frame = new Frame("AWTDemo");
frame.addWindowListener(new AdapterDemo());
frame.setLayout(new FlowLayout());
button1 = new Button("b1");
button2 = new Button("b2");
button3 = new Button("b3");
button4 = new Button("b4");
button5 = new Button("b5");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
frame.add(button1);
frame.add(button2);
frame.add(button3);
frame.add(button4);
frame.add(button5);
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
frame.removeAll();
}
}
class AdapterDemo extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:removeAllDemo.java
功能:示範 Java 程式
作者:張凱慶
時間:西元 2012 年 3 月 */此例建立 frame 之後,依次建立五個按鈕
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 的 removeAll() ,從 frame 中移除掉所有按鈕的參考變數
public void actionPerformed(ActionEvent e) {
frame.removeAll();
}編譯後執行,點擊任一按鈕結果如下

| 中英文術語對照 | |
|---|---|
| 類別 | class |
| 方法 | method |
| 回傳值 | return value |
| 型態 | type |
| 物件 | object |
| 參數 | parameter |
您可以繼續參考
AWT 元件
相關目錄
Java API 分類導覽
Java 教材
首頁
參考資料
http://docs.oracle.com/javase/6/docs/api/java/awt/Container.html
沒有留言:
張貼留言